elasticsearch 7.2源码编译

环境

  • gradle
  • JDK 12

下载源码

1
git clone https://github.com/elastic/elasticsearch.git

拉取项目下来先不导入到IDEA,如果之前已经导入,删除.idea和elasticsearch.iml

编译项目

在命令行完成

1
2
3
4
5
6
7
cd elasticsearch

# 编译项目打包
./gradlew assemble

# 编译为idea项目
./gradlew idea

以上完成后将项目导入到IDEA

运行server

在IDEA中配置项目

IDEA Run->Edit Configurations

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Main Class: 
org.elasticsearch.bootstrap.Elasticsearch


VM options:
-Des.path.home=/Users/struy/project/github/elasticsearch/distribution/build/run
-Des.path.conf=/Users/struy/project/github/elasticsearch/distribution/build/run
-Didea.no.launcher=true
-Dlog4j2.disable.jmx=true
-Xms1g
-Xmx1g

# /Users/struy/project/github/elasticsearch/distribution/build/run 这个目录可以自定义,但是前提目录必须存在

# build的 config
cp -R ./distribution/build/outputs/default/ /Users/struy/project/github/elasticsearch/distribution/build/run

touch /Users/struy/project/github/elasticsearch/distribution/build/run/elasticsearch.yml

vi /Users/struy/project/github/elasticsearch/distribution/build/run/elasticsearch.yml

# 填入
node.name: local-node-1

可能的错误

1
2
3
4
5
6
7
Caused by: java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "createClassLoader")

# 在以下文件中
$JAVA_HOME/jre/lib/security/java.policy

# 新增
permission java.lang.RuntimePermission "createClassLoader";