美文网首页
idea调试elasticsearch7.10.3

idea调试elasticsearch7.10.3

作者: 康英永 | 来源:发表于2021-10-11 16:03 被阅读0次

一、下载es源码,下载后先不着急导入idea

代码网址:https://github.com/elastic/elasticsearch

git路径:https://github.com/elastic/elasticsearch.git

执行git checkout -b 7.10 origin/7.10,切换到7.10分支

源码路径根路径记作$es_code_root,方便下文使用

二、配置jdk和gradle

2.1、安装jdk

从$es_code_root/CONTRIBUTING.md中查找jdk版本,具体为下面一段话:

JDK 14 is required to build Elasticsearch. You must have a JDK 14 installation

with the environment variable`JAVA_HOME` referencing the path to Java home for

your JDK 14 installation. By default, ...

jdk版本下载路径,可以使用清华的镜像:https://mirrors.tuna.tsinghua.edu.cn/AdoptOpenJDK/,下载相应的版本安装后,配置JAVA_HOME为安装路径,配置完毕,运行java -version查看是否安装成功。

2.2、安装gradle

从$es_code_root/gradle/wrapper/gradle-wrapper.properties中查找gradle版本,具体内容如下:

distributionBase=GRADLE_USER_HOME

distributionPath=wrapper/dists

distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-all.zip

zipStoreBase=GRADLE_USER_HOME

zipStorePath=wrapper/dists

distributionSha256Sum=11657af6356b7587bfb37287b5992e94a9686d5c8a0a1b60b87b9928a2decde5

可以使用sdkman安装gradle,命令为sdk install gradle 6.6.1,安装完毕,使用gradle -version查看是否安装成功。

2.3、gradle配置阿里云仓库

进入gradle的安装目录后,在init.d目录下创建文件init.gradle,并将以下配置信息写入init.gradle后保存。

allprojects{

    repositories {

        def ALIYUN_REPOSITORY_URL = 'https://maven.aliyun.com/repository/public/'

        def ALIYUN_GRADLE_PLUGIN_URL = 'https://maven.aliyun.com/repository/gradle-plugin/'

        all { ArtifactRepository repo ->

            if(repo instanceof MavenArtifactRepository){

                def url = repo.url.toString()

                if (url.startsWith('https://repo1.maven.org/maven2/')) {

                    project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."

                    remove repo

                }

                if (url.startsWith('https://jcenter.bintray.com/')) {

                    project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."

                    remove repo

                }

                if (url.startsWith('https://plugins.gradle.org/m2/')) {

                    project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_GRADLE_PLUGIN_URL."

                    remove repo

                }

            }

        }

        maven { url ALIYUN_REPOSITORY_URL }

        maven { url ALIYUN_GRADLE_PLUGIN_URL }

    }

}

三、编译es

进入es源码根目录$es_code_root,./gradlew localDistro,显示如下信息说明编译成功。

Elasticsearch distribution installed to $es_code_root/build/distribution/local.

BUILD SUCCESSFUL in 1m 23s

四、部署编译好的es

将编译好的es版本$es_code_root/build/distribution/local/elasticsearch-7.10.3-SNAPSHOT拷贝到自己的服务发布路径,并重命名为elasticsearch-7.10.3,比如:/Users/***/Applications/elasticsearch-7.10.3,将es版本路径记作$es_app_root,方便下文使用。

进入$es_app_root,使用./bin/elasticsearch运行es,启动后,在浏览器输入http://localhost:9200/,显示如下信息证明启动成功:

五、导入es源码到idea

5.1、导入源码并配置jdk和gradle

打开idea,点击File/Open,选择$es_code_root/build.gradle,选择open as product,需要等待几分钟,导入完成后,点击File/Product Structure...配置jdk,并点击IntelliJ IDEA/Preferences...,搜索gradle,配置gradle路径,Gradle JVM选择相应的jdk版本。

5.2、运行es源码

idea中点击$es_code_root/server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java,找到main函数,右键点击Run 'Elasticsearch main()',会运行错误,然后点击Run/Edit Configurations...,在VM options中填入以下配置,切记将$es_app_root修改为自己在第四步中es服务的根路径:

-Des.path.conf=$es_app_root/config

-Des.path.home=$es_app_root

-Dlog4j2.disable.jmx=true

-Djava.security.policy=$es_app_root/config/java.policy

然后在$es_app_root/config目录下创建文件java.policy,并写入以下配置:

grant {

    permission java.lang.RuntimePermission "createClassLoader";

    permission java.lang.RuntimePermission "setContextClassLoader";

};

然后,打开$es_app_root/config/elasticsearch.yml,去掉#node.name: node-1的“#”。

然后,运行Elasticsearch即可,待启动后,在浏览器输入http://localhost:9200/,显示类似第四步骤中的信息则证明启动成功:

如果出现异常信息“java.lang.NoClassDefFoundError: org/elasticsearch/plugins/ExtendedPluginsClassLoader”,则重新打开Run Configuration,勾选 include dependency with provided scope后,重新运行即可。如果还是报该异常,则可尝试修改server模块下的build.gradle中的compileOnly project(':libs:plugin-classloader')为compile project(':libs:plugin-classloader') 。

六、参考文档

1、idea导入Elasticsearch 7.10.2源码和编译运行,https://copyfuture.com/blogs-details/20210327133933335M

2、在Windows环境IDEA下编译运行Elasticsearch 7.14.1,https://blog.csdn.net/weixin_43820556/article/details/120165948

3、IDEA 编译 ElasticSearch 7.8.1,https://blog.csdn.net/ShelleyLittlehero/article/details/107642951

4、ElasticSearch-7.8.0 源码编译调试 (详细),https://zhuanlan.zhihu.com/p/188725714

5、idea源码调试的问题,https://elasticsearch.cn/question/8243

相关文章

  • idea调试elasticsearch7.10.3

    一、下载es源码,下载后先不着急导入idea 代码网址:https://github.com/elastic/el...

  • Idea重构

    Intellij idea使用教程与心得 Intellij idea的调试总结 Idea重构 IDEA模板与对比

  • AndroidStudio 动态调试Smali代码

    AndroidStudio调试方式其实和IDEA调试方式比较类似,毕竟是基于IDEA开发的。 优点是:断点可以打的...

  • Idea 调试

    功能键 直接看图,详细解释,每一个按钮(按钮对应图中的数字)都是什么功能。 1,rerun XXX,这个就是直接重...

  • idea调试

    添加书签:f11 使用助记键添加/删除书签:ctrl +f11 弹出层,显示书签:shift +f11 快速添加助...

  • Android逆向-动态调试环境搭建记录

    常见Android调试方法简介: 1.IDEA/Android Studio + SmaliIdea插件 可调试s...

  • 调试环境

    调试环境 我使用的调试的环境是: idea sqoop 1.99.6 调试使用的代码 maven依赖 下面是项目使...

  • IDEA远程调试Spark

    1.前言 本文讲述如何使用IDEA远程调试spark,这里所说的调试spark包括: 调试spark应用程序,也就...

  • SpringBoot项目IDEA开启远程调试

    title: SpringBoot项目IDEA开启远程调试author: XDiongavatar: https:...

  • Intellij IDEA 2017 debug断点调试技巧与总

    Intellij IDEA 2017 debug断点调试技巧与总结详解篇

网友评论

      本文标题:idea调试elasticsearch7.10.3

      本文链接:https://www.haomeiwen.com/subject/srbloltx.html