ElasticSearch 2.0 java api JarHell problems

I have also encounter this problem with IntelliJ when I tested the internalenginetest.

/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/bin/java...

java.lang.RuntimeException: found jar hell in test classpath
at org.elasticsearch.bootstrap.BootstrapForTesting.(BootstrapForTesting.java:89)
at org.elasticsearch.test.ESTestCase.(ESTestCase.java:117)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at com.carrotsearch.randomizedtesting.RandomizedRunner$2.run(RandomizedRunner.java:585)
Caused by: java.lang.IllegalStateException: jar hell!
class: jdk.packager.services.UserJvmOptionsService
jar1: /Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/lib/ant-javafx.jar
jar2: /Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/lib/packager.jar
at org.elasticsearch.bootstrap.JarHell.checkClass(JarHell.java:282)
at org.elasticsearch.bootstrap.JarHell.checkJarHell(JarHell.java:186)
at org.elasticsearch.bootstrap.JarHell.checkJarHell(JarHell.java:87)
at org.elasticsearch.bootstrap.BootstrapForTesting.(BootstrapForTesting.java:87)
... 4 more

Disconnected from the target VM, address: '127.0.0.1:51245', transport: 'socket'

I have solved this problem by misconfigured the two jars and thank you!

Hi Everyone,
I am facing the issue with jar hell while running the unit test.

java.lang.RuntimeException: found jar hell in test classpath
    at org.elasticsearch.bootstrap.BootstrapForTesting.<clinit>(BootstrapForTesting.java:95)
    at org.elasticsearch.test.ESTestCase.<clinit>(ESTestCase.java:99)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at com.carrotsearch.randomizedtesting.RandomizedRunner$2.run(RandomizedRunner.java:585)
Caused by: java.lang.IllegalStateException: jar hell!
class: org.apache.commons.io.CopyUtils
jar1: C:\Users\vvenkatasubbu\.gradle\caches\modules-2\files-2.1\commons-io\commons-io\1.3.2\b6dde38349ba9bb5e6ea6320531eae969985dae5\commons-io-1.3.2.jar
jar2: C:\Users\vvenkatasubbu\.gradle\caches\modules-2\files-2.1\org.apache.commons\commons-io\1.3.2\b6dde38349ba9bb5e6ea6320531eae969985dae5\commons-io-1.3.2.jar
    at org.elasticsearch.bootstrap.JarHell.checkClass(JarHell.java:282)
    at org.elasticsearch.bootstrap.JarHell.checkJarHell(JarHell.java:186)
    at org.elasticsearch.bootstrap.JarHell.checkJarHell(JarHell.java:87)
    at org.elasticsearch.bootstrap.BootstrapForTesting.<clinit>(BootstrapForTesting.java:93)
    ... 4 more

I have got the error like above, resolved those by removing the unnecessary jar file.

But i am facing the issue with the following two jar namely tomcat-embed-core-8.0.36.jar and hibernate-jpa-2.1-api-1.0.0.Final.jar. There is one common class between these two i need both the jar file, can anyone explain me how to resolve the issue.

java.lang.RuntimeException: found jar hell in test classpath
        at org.elasticsearch.bootstrap.BootstrapForTesting.<clinit>(BootstrapForTesting.java:95)
        at org.elasticsearch.test.ESTestCase.<clinit>(ESTestCase.java:99)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:348)
        at com.carrotsearch.randomizedtesting.RandomizedRunner$2.run(RandomizedRunner.java:585)
    Caused by: java.lang.IllegalStateException: jar hell!
    class: javax.persistence.PersistenceProperty
    jar1: C:\Users\vvenkatasubbu\.gradle\caches\modules-2\files-2.1\org.apache.tomcat.embed\tomcat-embed-core\8.0.36\de87fa65671daad59773c8280eeabbd335f42c\tomcat-embed-core-8.0.36.jar
    jar2: C:\Users\vvenkatasubbu\.gradle\caches\modules-2\files-2.1\org.hibernate.javax.persistence\hibernate-jpa-2.1-api\1.0.0.Final\5e731d961297e5a07290bfaf3db1fbc8bbbf405a\hibernate-jpa-2.1-api-1.0.0.Final.jar
        at org.elasticsearch.bootstrap.JarHell.checkClass(JarHell.java:282)
        at org.elasticsearch.bootstrap.JarHell.checkJarHell(JarHell.java:186)
        at org.elasticsearch.bootstrap.JarHell.checkJarHell(JarHell.java:87)
        at org.elasticsearch.bootstrap.BootstrapForTesting.<clinit>(BootstrapForTesting.java:93)
        ... 4 more

Thanks in advance.

Not really sure what you can do.

Some ideas:

  • remove hibernate-jpa-2.1-api-1.0.0.Final.jar from your classpath (from your gradle deps)
  • repackage one of those libs and remove all classes which are in double
  • Don't use Tomcat Embedded but another container

Sorry no real concrete solutions here. For sure, it's bad that you have the same class twice within the same classloader.

And BTW you should open your own thread for your questions (and eventually link to the older thread as reference)

I am using hibernate JPA for SQL related bindings.

I understand that but may be you don't need this JAR if all the classes are already provided by Tomcat?

tomcat only provided the above class, but the other persistence re-queried classes were in hibernate jpa.

So you can may be replace you tomcat jar by your version where you exclude this class?
May be look at Maven shade plugin for this?

yes, I am trying to replace the jar with other library for the replacement.

But doesn't got exact one.