gpt4 book ai didi

elasticsearch - 使用 IntelliJ 中的 Elasticsearch 测试框架,如何解决关于 idea_rt.jar 的 jar hell ?

转载 作者:行者123 更新时间:2023-12-02 12:36:10 25 4
gpt4 key购买 nike

我正在尝试使用提供的 Elasticsearch java 测试框架对我的 es 项目进行一些集成测试。我在 IntelliJ 中有一个非常简单的测试设置:

class FormTest : ESIntegTestCase() {

override fun nodeSettings(nodeOrdinal: Int): Settings = Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
//.put("node.mode", "network")
.build()

@org.junit.Test fun start() {
ensureGreen()
}
}

但是,当我运行它时,我得到以下异常:

java.lang.RuntimeException: found jar hell in test classpath

at org.elasticsearch.bootstrap.BootstrapForTesting.<clinit>(BootstrapForTesting.java:92)
at org.elasticsearch.test.ESTestCase.<clinit>(ESTestCase.java:190)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at com.carrotsearch.randomizedtesting.RandomizedRunner$2.run(RandomizedRunner.java:592)
Caused by: java.lang.IllegalStateException: jar hell!
duplicate jar [C:\Users\user\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\181.5281.24\lib\idea_rt.jar] on classpath: ...
at org.elasticsearch.bootstrap.JarHell.parseClassPath(JarHell.java:142)
at org.elasticsearch.bootstrap.JarHell.parseClassPath(JarHell.java:98)
at org.elasticsearch.bootstrap.JarHell.checkJarHell(JarHell.java:89)
at org.elasticsearch.bootstrap.BootstrapForTesting.<clinit>(BootstrapForTesting.java:90)
... 4 more

我找到了一些绕过jar hell 检查的方法,但是如何解决这个问题?

最佳答案

我偶然发现时遇到了同样的问题:https://github.com/elastic/elasticsearch/blob/master/CONTRIBUTING.md#configuring-ides-and-running-tests

特别是,我必须设置 idea.no.launcher=true 并重新启动我的 IntelliJ。

In order to run tests directly from IDEA 2017.2 and above, it is required to disable the IDEA run launcher in order to avoid idea_rt.jar causing "jar hell". This can be achieved by adding the -Didea.no.launcher=true JVM option. Alternatively, idea.no.launcher=true can be set in the idea.properties

另外,您可能需要:

For IDEA 2017.3 and above, in addition to the JVM option, you will need to go to Run->Edit Configurations->...->Defaults->JUnit and verify that the Shorten command line setting is set to user-local default: none. You may also need to remove ant-javafx.jar from your classpath if that is reported as a source of jar hell.

最后,确保你有断言:

The Elasticsearch codebase makes heavy use of Java asserts and the test runner requires that assertions be enabled within the JVM. This can be accomplished by passing the flag -ea to the JVM on startup.

关于elasticsearch - 使用 IntelliJ 中的 Elasticsearch 测试框架,如何解决关于 idea_rt.jar 的 jar hell ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51045201/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com