目录
- 一、环境说明
- 二、基础环境搭建
- 2.1 安装jdk
- 2.2 安装gradle
- 三、源码阅读环境搭建步骤
- 3.1 源码下载
- 3.2 导入IDEA
- 3.3 编译打包
- 四、调试Elasticsearch
- 4.1本地运行
一、环境说明
操作系统 | Windows11 |
JDK版本 | OpenJDK12 |
Elasticsearch源码版本 | elasticsearch6.8 |
Gradle版本 | gradle-5.4.1 |
IDEA版本 | IntelliJ IDEA 2021.1 |
二、基础环境搭建
2.1 安装jdk
下载jdk-12,jdk-12下载地址
解压openjdk-12+32_windows-x64_bin.zip 到D:\Program Files\Java
配置环境变量
2.2 安装gradle
解压gradle-5.4.1-all.zip到D盘
配置环境变量
三、源码阅读环境搭建步骤
3.1 源码下载
3.1.1 手动下载
进入GitHub官网,选择6.8分之,下载源码
3.1.2 idea git插件下载
File → New → Project fromVersion Control
切换分之为6.8
3.2 导入IDEA
导入代码到IDEA,之后进行jdk和gradle设置
设置jdk
设置gradle
3.3 编译打包
idea的Terminal控制台执行命令
gradlew assemble
打包的文件在distribution/archives模块中
Reload project
复制elasticsearch-6.8.23-SNAPSHOT.zip到E:\opt\es文件夹下,并解压改名为elasticsearch-6.8
四、调试Elasticsearch
4.1 本地运行
运行server模块的 org.elasticsearch.bootstrap.Elasticsearch 类
报错如下
点击Run → Edit Configurations
增加VM Opinton配置
-Des.path.home=E:\opt\es\elasticsearch-6.8
-Des.path.conf=E:\opt\es\elasticsearch-6.8\config
-Xms1g
-Xmx1g
-Dlog4j2.disable.jmx=true
-Djava.security.policy=E:\opt\es\elasticsearch-6.8\config\elasticsearch.policy
在E:\opt\es\elasticsearch-6.8\config文件夹中增加elasticsearch.policy文件,内容为
grant {
permission javax.management.MBeanTruxtPermission "register";
permission javax.management.MBeanServerPermission "createMBeanServer";
permission java.lang.RuntimePermission "createClassLoader";
};
启动Elasticsearch
[2022-01-02T21:42:43,108][ERROR][o.e.b.ElasticsearchUncaughtExceptionHandler] [hfeiN1g] fatal error in thread [main], exiting
java.lang.NoClassDefFoundError: org/elasticsearch/plugins/ExtendedPluginsClassLoader
at org.elasticsearch.plugins.PluginsService.loadBundle(PluginsService.java:547) ~[classes/:?]
at org.elasticsearch.plugins.PluginsService.loadBundles(PluginsService.java:473) ~[classes/:?]
at org.elasticsearch.plugins.PluginsService.<init>(PluginsService.java:163) ~[classes/:?]
at org.elasticsearch.node.Node.<init>(Node.java:339) ~[classes/:?]
at org.elasticsearch.node.Node.<init>(Node.java:266) ~[classes/:?]
at org.elasticsearch.bootstrap.Bootstrap$5.<init>(Bootstrap.java:212) ~[classes/:?]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:212) ~[classes/:?]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:333) ~[classes/:?]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[classes/:?]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[classes/:?]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[classes/:?]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[classes/:?]
at org.elasticsearch.cli.Command.main(Command.java:90) ~[classes/:?]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:116) ~[classes/:?]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[classes/:?]
Caused by: java.lang.ClassNotFoundException: org.elasticsearch.plugins.ExtendedPluginsClassLoader
at jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583) ~[?:?]
at jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) ~[?:?]
at java.lang.ClassLoader.loadClass(ClassLoader.java:521) ~[?:?]
... 15 more
上述错误是由于IDEA配置不对造成
修改结果参考下图
a) gradle配置修改
Edit Configuration
运行
org.elasticsearch.bootstrap.Elasticsearch
浏览器访问