Trivial NodeBuilder Java code resulting in "jar hell" error

This code

package threepieces.esonly;

import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.node.NodeBuilder;

public class TrivialNode {

    public static void main(String[] argsIgnored) {
        Settings settings = Settings.settingsBuilder()
                .put("path.home", "/Applications/elasticsearch-2.0.0/")
                .put("", "epsteinj-elasticsearch-local")
                .put("http.enabled", true)
                .put("index.number_of_shards", 1)
                .put("index.number_of_replicas", 1).build();

        Client client = NodeBuilder.nodeBuilder().settings(settings).client(true).node().client();

Causes this error

Exception in thread "main" java.lang.IllegalStateException: failed to load bundle [file:/Applications/elasticsearch-2.0.0/plugins/license/license-2.0.0.jar, file:/Applications/elasticsearch-2.0.0/plugins/license/license-core-2.0.0.jar, file:/Applications/elasticsearch-2.0.0/plugins/license/license-plugin-api-2.0.0.jar, file:/Applications/elasticsearch-2.0.0/plugins/marvel-agent/marvel-agent-2.0.0.jar] due to jar hell
    at org.elasticsearch.plugins.PluginsService.loadBundles(
    at org.elasticsearch.plugins.PluginsService.(
    at org.elasticsearch.node.Node.(
    at org.elasticsearch.node.NodeBuilder.node(
    at threepieces.esonly.TrivialNode.main(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.lang.reflect.Method.invoke(
    at com.intellij.rt.execution.application.AppMain.main(
Caused by: java.lang.IllegalStateException: jar hell!
jar1: /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/lib/ant-javafx.jar
jar2: /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/lib/packager.jar
    at org.elasticsearch.bootstrap.JarHell.checkClass(
    at org.elasticsearch.bootstrap.JarHell.checkJarHell(
    at org.elasticsearch.plugins.PluginsService.loadBundles(
    ... 10 more

Any ideas why?

You've got a class defined in two places on the classpath:

jar1: /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/lib/ant-javafx.jar
jar2: /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/lib/packager.jar

This has caused tons of subtle issues in the past so in 2.0 we try to detect when it happens and be paranoid about it.

I saw a jar-hell related bug in another ElasticSearch forum, so I assumed it was a related bug and didn't look carefully enough at the error message.

I've removed ant-javafx.jar from the JDK, and it now works. But it honestly seems like an odd thing to have to do--alter some files from the default installation of the Oracle JDK. But for now, I don't use JavaFX anywhere, so hopefully this won't cause other problems.

Thanks for you help.

You should not touch the JDK installation itself but just change how IntelliJ declares it. By default IntelliJ adds all those jars when you define the Java SDK. Change that on IntelliJ side.

I have encountered a similar jar hell problem, but with two different jar files :
jar 1: jasper-runtime-5.5.15.jar
jar 2 : jasper-compiler-5.5.15.jar

Do you have any solution to this problem?


You need to get rid of one jar to avoid this problem.
You can use maven to stop one jar coming to your project.