你可以的,加油

idea源码调试的问题

Elasticsearch | 作者 code4j | 发布于2019年09月06日 | 阅读数:7065

es版本6.6. idea调试。
 
VM options 配置如下:
 
-Des.path.home=/Users/code4j/software/elasticsearch6-1
-Des.path.conf=/Users/code4j/software/elasticsearch6-1/config
-Dlog4j2.disable.jmx=true
-Djava.security.policy=/Users/code4j/software/elasticsearch6-1/config/java.policy
 
路径都验证过没有写错。
 
启动后报错提示:
 
> Task :server:Elasticsearch.main() FAILED
ERROR: the system property [es.path.conf] must be set

FAILURE: Build failed with an exception.
 
 
改了好几次以后,发现都不生效。。 有遇到跟我一个情况的么
 
 
--------------------------更新--------------------------
 [es.path.conf] must be set的问题解决了,重新编辑了几次就好了。。很奇怪,现在出现一个新的问题:
 
idea启动报错信息如下:
java.lang.NoClassDefFoundError: org/elasticsearch/plugins/ExtendedPluginsClassLoader
at org.elasticsearch.plugins.PluginsService.loadBundle(PluginsService.java:545) ~[main/:?]
at org.elasticsearch.plugins.PluginsService.loadBundles(PluginsService.java:471) ~[main/:?]
at org.elasticsearch.plugins.PluginsService.<init>(PluginsService.java:163) ~[main/:?]
at org.elasticsearch.node.Node.<init>(Node.java:339) ~[main/:?]
at org.elasticsearch.node.Node.<init>(Node.java:266) ~[main/:?]
at org.elasticsearch.bootstrap.Bootstrap$5.<init>(Bootstrap.java:212) ~[main/:?]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:212) ~[main/:?]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:333) ~[main/:?]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[main/:?]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[main/:?]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[main/:?]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.7.3-SNAPSHOT.jar:?]
at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.7.3-SNAPSHOT.jar:?]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:116) ~[main/:?]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[main/:?]
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

> Task :server:Elasticsearch.main() FAILED

 
这个问题网上的解决方案是 idea 的 run configuration 有一个 include dependency with provided scope的选项,但是在我这边勾选后启动依然会报这个。。  无奈只能选择网上使用 remote debug先启动了。。。   不知道有没有和我一样的同学,ide启动和网上步骤一模一样但是依旧解决不了问题。。
 
感慨一波: 6.x以后的版本控制改成了gradle之后感觉比maven麻烦了很多,而且相比之前看2.x/5.x代码的时候启动时多了很多杂乱的日志,,可能是我还不熟悉吧。
 
 --------------------------------- 分割线 -----------------------------------
 
最后一个问题也终于解决了,特地记录一下。网上的那个勾选 include dependency with provided scope 在我这里不好使,我找到了另一个方法:
 
修改server模块下的build.gradle中的compileOnly project(':libs:plugin-classloader')为compile project(':libs:plugin-classloader') 原文地址: https://www.jianshu.com/p/fbb28ffecc5a
 
网上看了下compileOnly的解释,其实和maven一样·就是不参与打包,换成compile就可以了,高版本把provided改成了compileOnly,所以可能那个选项不生效了。
https://www.jianshu.com/p/f34c179bc9d0
 
 
已邀请:

code4j - coder github: https://github.com/rpgmakervx

赞同来自: hapjin

自己回复一下,问题解决,有源码调试需求的同学可以看下最后的解决方案

hapjin

赞同来自: MichaelXoX

我又在 mac git clone了一份ES7.3.0版本的源码,debug org.elasticsearch.bootstrap.Elasticsearch#main(java.lang.String[]) 的时候报:java.lang.NoClassDefFoundError: org/elasticsearch/plugins/ExtendedPluginsClassLoader
 
把server模块下的build.gradle:
compileOnly project(':libs:elasticsearch-plugin-classloader')  改成:compile project(':libs:elasticsearch-plugin-classloader')
就能启动了,经过测试没问题。


curl -X GET "localhost:9200/_cat/master?v&pretty"
(base) ➜  ~ curl -X GET "localhost:9200/_cat/master?v&pretty"
id                     host      ip        node
mqo3fOSbS0GJHV1SxcQEoA 127.0.0.1 127.0.0.1 debug_node


 
在 git clone下来的ES源码"主目录下"   执行 ./gradlew idea 会自动下载安装合适版本的gradle。
 
Gradle 5.5
(base) ➜  ~ java -version
java version "12.0.2" 2019-07-16
Java(TM) SE Runtime Environment (build 12.0.2+10)
Java HotSpot(TM) 64-Bit Server VM (build 12.0.2+10, mixed mode, sharing)
 

hapjin

赞同来自:

贴一下我的ES6.3.2的源码IDEA启动配置参数:


-Des.path.conf=/home/panda/software/es_debug/elasticsearch-6.3.2/config -Des.path.home=/home/panda/software/es_debug/elasticsearch-6.3.2 -Dlog4j2.disable.jmx=true -Djava.security.policy=/home/panda/software/es_debug/elasticsearch-6.3.2/config/java.policy


有时候,觉得vm options 参数不生效的话,其实在 IDEA console 控制台第一行启动的时候会打印启动配置参数的(默认被IDEA折叠了,展开即可)
我的环境是:ElasticSearch6.3.2,Ubuntu16.04,JDK8,IDEA2018,gardle4.7
参考的:这篇文章
 


/usr/local/jdk1.8.0_144/bin/java -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:38359,suspend=y,server=n -Des.path.conf=/home/panda/software/es_debug/elasticsearch-6.3.2/config -Des.path.home=/home/panda/software/es_debug/elasticsearch-6.3.2 -Dlog4j2.disable.jmx=true -Djava.security.policy=/home/panda/software/es_debug/elasticsearch-6.3.2/config/java.policy -javaagent:/home/panda/software/idea-IU-182.4892.20/plugins/Groovy/lib/agent/gragent.jar -javaagent:/home/panda/software/idea-IU-182.4892.20/lib/rt/debugger-agent.jar=file:/tmp/capture.props -Dfile.encoding=UTF-8 -classpath /usr/local/jdk1.8.0_144/jre/lib/charsets.jar:/usr/local/jdk1.8.0_144/jre/lib/deploy.jar:/usr/local/jdk1.8.0_144/jre/lib/ext/cldrdata.jar:/usr/local/jdk1.8.0_144/jre/lib/ext/dnsns.jar:/usr/local/jdk1.8.0_144/jre/lib/ext/jaccess.jar:/usr/local/jdk1.8.0_144/jre/lib/ext/jfxrt.jar:/usr/local/jdk1.8.0_144/jre/lib/ext/localedata.jar:/usr/local/jdk1.8.0_144/jre/lib/ext/nashorn.jar:/usr/local/jdk1.8.0_144/jre/lib/ext/sunec.jar:/usr/local/jdk1.8.0_144/jre/lib/ext/sunjce_provider.jar:/usr/local/jdk1.8.0_144/jre/lib/ext/sunpkcs11.jar:/usr/local/jdk1.8.0_144/jre/lib/ext/zipfs.jar:/usr/local/jdk1.8.0_144/jre/lib/javaws.jar:/usr/local/jdk1.8.0_144/jre/lib/jce.jar:/usr/local/jdk1.8.0_144/jre/lib/jfr.jar:/usr/local/jdk1.8.0_144/jre/lib/jfxswt.jar:/usr/local/jdk1.8.0_144/jre/lib/jsse.jar:/usr/local/jdk1.8.0_144/jre/lib/management-agent.jar:/usr/local/jdk1.8.0_144/jre/lib/plugin.jar:/usr/local/jdk1.8.0_144/jre/lib/resources.jar:/usr/local/jdk1.8.0_144/jre/lib/rt.jar:/home/panda/ideaProjects/elasticsearch/elasticsearch-6.3.2/server/build-idea/classes/main:/home/panda/ideaProjects/elasticsearch/elasticsearch-6.3.2/libs/x-content/build-idea/classes/main:/home/panda/ideaProjects/elasticsearch/elasticsearch-6.3.2/server/cli/build-idea/classes/main:/home/panda/ideaProjects/elasticsearch/elasticsearch-6.3.2/libs/elasticsearch-core/build-idea/classes/main:/home/panda/.gradle/caches/modules-2/files-2.1/org.apache.lucene/lucene-core/7.3.1/ce76b4aef66ffe0830afefb2b347028a4fc9eb36/lucene-core-7.3.1.jar:/home/panda/.gradle/caches/modules-2/files-2.1/org.apache.lucene/lucene-analyzers-common/7.3.1/51b62b22f4193bfa386f5ca0c978c68821a12bc0/lucene-analyzers-common-7.3.1.jar:/home/panda/.gradle/caches/modules-2/files-2.1/org.apache.lucene/lucene-backward-codecs/7.3.1/c9bded879284d12b66eb8df112b6f69078616bb6/lucene-backward-codecs-7.3.1.jar:/home/panda/.gradle/caches/modules-2/files-2.1/org.apache.lucene/lucene-grouping/7.3.1/ebb5344ee066bbb6031164dcf4e690d5a4ea62a5/lucene-grouping-7.3.1.jar:/home/panda/.gradle/caches/modules-2/files-2.1/org.apache.lucene/lucene-highlighter/7.3.1/1e945c65876a1eab97a5db40e92c981c5a65915/lucene-highlighter-7.3.1.jar:/home/panda/.gradle/caches/modules-2/files-2.1/org.apache.lucene/lucene-join/7.3.1/e866b2c36555cff48f31a427efbfd52466418504/lucene-join-7.3.1.jar:/home/panda/.gradle/caches/modules-2/files-2.1/org.apache.lucene/lucene-memory/7.3.1/12b7520cfb0c83d4d9e4efde6ad1812693f91acd/lucene-memory-7.3.1.jar:/home/panda/.gradle/caches/modules-2/files-2.1/org.apache.lucene/lucene-misc/7.3.1/2ce12b8828f29c8e5dd9eeef05333705befc9342/lucene-misc-7.3.1.jar:/home/panda/.gradle/caches/modules-2/files-2.1/org.apache.lucene/lucene-queries/7.3.1/d531efe427da6cb41a9aa52854be4dd241227a19/lucene-queries-7.3.1.jar:/home/panda/.gradle/caches/modules-2/files-2.1/org.apache.lucene/lucene-queryparser/7.3.1/51e4cde15df3ab4534a6407598cfb5c7ce7d21ac/lucene-queryparser-7.3.1.jar:/home/panda/.gradle/caches/modules-2/files-2.1/org.apache.lucene/lucene-sandbox/7.3.1/ba8c7a91cf3d74d7f5e6f91e6842c6e857bd73c5/lucene-sandbox-7.3.1.jar:/home/panda/.gradle/caches/modules-2/files-2.1/org.apache.lucene/lucene-spatial/7.3.1/6e5fb097fdb41f1817c748e4b1d4e6b9bb6e92ec/lucene-spatial-7.3.1.jar:/home/panda/.gradle/caches/modules-2/files-2.1/org.apache.lucene/lucene-spatial-extras/7.3.1/7ff14f7c7b8e2fb7259e925949f51122cbc873c4/lucene-spatial-extras-7.3.1.jar:/home/panda/.gradle/caches/modules-2/files-2.1/org.apache.lucene/lucene-spatial3d/7.3.1/db59b01557dd4abb1a469d857e2a96b3c3aa6365/lucene-spatial3d-7.3.1.jar:/home/panda/.gradle/caches/modules-2/files-2.1/org.apache.lucene/lucene-suggest/7.3.1/5255e5bec27f078ca89cdc44b9614e3295b51607/lucene-suggest-7.3.1.jar:/home/panda/.gradle/caches/modules-2/files-2.1/com.carrotsearch/hppc/0.7.1/8b5057f74ea378c0150a1860874a3ebdcb713767/hppc-0.7.1.jar:/home/panda/.gradle/caches/modules-2/files-2.1/joda-time/joda-time/2.9.9/f7b520c458572890807d143670c9b24f4de90897/joda-time-2.9.9.jar:/home/panda/.gradle/caches/modules-2/files-2.1/com.tdunning/t-digest/3.2/2ab94758b0276a8a26102adf8d528cf6d0567b9a/t-digest-3.2.jar:/home/panda/.gradle/caches/modules-2/files-2.1/org.hdrhistogram/HdrHistogram/2.1.9/e4631ce165eb400edecfa32e03d3f1be53dee754/HdrHistogram-2.1.9.jar:/home/panda/.gradle/caches/modules-2/files-2.1/org.locationtech.spatial4j/spatial4j/0.7/faa8ba85d503da4ab872d17ba8c00da0098ab2f2/spatial4j-0.7.jar:/home/panda/.gradle/caches/modules-2/files-2.1/org.locationtech.jts/jts-core/1.15.0/705981b7e25d05a76a3654e597dab6ba423eb79e/jts-core-1.15.0.jar:/home/panda/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-api/2.9.1/7a2999229464e7a324aa503c0a52ec0f05efe7bd/log4j-api-2.9.1.jar:/home/panda/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-core/2.9.1/c041978c686866ee8534f538c6220238db3bb6be/log4j-core-2.9.1.jar:/home/panda/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-1.2-api/2.9.1/894f96d677880d4ab834a1356f62b875e579caaa/log4j-1.2-api-2.9.1.jar:/home/panda/.gradle/caches/modules-2/files-2.1/org.elasticsearch/jna/4.5.1/da10908ae23dc59b19dc258e63aea1c44621dc3a/jna-4.5.1.jar:/home/panda/ideaProjects/elasticsearch/elasticsearch-6.3.2/libs/secure-sm/build-idea/classes/main:/home/panda/.gradle/caches/modules-2/files-2.1/org.yaml/snakeyaml/1.17/7a27ea250c5130b2922b86dea63cbb1cc10a660c/snakeyaml-1.17.jar:/home/panda/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-core/2.8.10/eb21a035c66ad307e66ec8fce37f5d50fd62d039/jackson-core-2.8.10.jar:/home/panda/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.dataformat/jackson-dataformat-smile/2.8.10/e853081fadaad3e98ed801937acc3d8f77580686/jackson-dataformat-smile-2.8.10.jar:/home/panda/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml/2.8.10/1e08caf1d787c825307d8cc6362452086020d853/jackson-dataformat-yaml-2.8.10.jar:/home/panda/ideaProjects/elasticsearch/elasticsearch-6.3.2/libs/plugin-classloader/build-idea/classes/main:/home/panda/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.dataformat/jackson-dataformat-cbor/2.8.10/1c58cc9313ddf19f0900cd61ed044874278ce320/jackson-dataformat-cbor-2.8.10.jar:/home/panda/.gradle/caches/modules-2/files-2.1/net.sf.jopt-simple/jopt-simple/5.0.2/98cafc6081d5632b61be2c9e60650b64ddbc637c/jopt-simple-5.0.2.jar:/home/panda/software/idea-IU-182.4892.20/lib/idea_rt.jar org.elasticsearch.bootstrap.Elasticsearch
 

pony_maggie - 公众号:犀牛饲养员的技术笔记

赞同来自:

你这个问题我也遇到过,我前两天刚在博客分享这个文章

要回复问题请先登录注册