3

I am trying to use the provided Elasticsearch java test framework to do some integration testing on my es project. I have a very simple test setup in 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()
    }
}

However, when I run this, I get the following exception:

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

I found some ways to bypass the jar hell check, but how to solve the issue?

2 Answers 2

6

I had the same problem when I stumbled across: https://github.com/elastic/elasticsearch/blob/master/CONTRIBUTING.md#configuring-ides-and-running-tests

In particular, I had to set idea.no.launcher=true and restart my 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

Also, you may need to:

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.

Finally, make sure you have asserts on:

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.

1
  • Thanks for your answer, I cannot verify this at the moment, but will accept it for now.
    – avolkmann
    Feb 20, 2019 at 8:12
2

Since I was surprised by how long my classpath was, I tried to use the shorten command line option, which worked.

Edit your run configuration and set the Shorten command line field to JAR manifest.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.