java.lang.ClassNotFoundException: org.bouncycastle.operator.OperatorCreationException

I wanted to try out X-Pack and when i run my spring application after adding the dependencies, I am getting the following error

Caused by: java.lang.NoClassDefFoundError: org/bouncycastle/operator/OperatorCreationException
	at java.lang.Class.getDeclaredConstructors0(Native Method) ~[na:1.8.0_172]
	at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671) ~[na:1.8.0_172]
	at java.lang.Class.getConstructors(Class.java:1651) ~[na:1.8.0_172]
	at org.elasticsearch.plugins.PluginsService.loadPlugin(PluginsService.java:426) ~[elasticsearch-6.1.2.jar:6.1.2]
	at org.elasticsearch.plugins.PluginsService.<init>(PluginsService.java:105) ~[elasticsearch-6.1.2.jar:6.1.2]
	at org.elasticsearch.client.transport.TransportClient.newPluginService(TransportClient.java:103) ~[elasticsearch-6.1.2.jar:6.1.2]
	at org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:128) ~[elasticsearch-6.1.2.jar:6.1.2]
	at org.elasticsearch.client.transport.TransportClient.<init>(TransportClient.java:262) ~[elasticsearch-6.1.2.jar:6.1.2]
	at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:128) ~[transport-6.1.2.jar:6.1.2]
	at org.elasticsearch.xpack.client.PreBuiltXPackTransportClient.<init>(PreBuiltXPackTransportClient.java:58) ~[x-pack-transport-6.1.2.jar:6.1.2]
	at org.elasticsearch.xpack.client.PreBuiltXPackTransportClient.<init>(PreBuiltXPackTransportClient.java:53) ~[x-pack-transport-6.1.2.jar:6.1.2]
	at org.elasticsearch.xpack.client.PreBuiltXPackTransportClient.<init>(PreBuiltXPackTransportClient.java:49) ~[x-pack-transport-6.1.2.jar:6.1.2]

Elasticsearch version - 6.1.2
Transport client version - 6.1.2
X-Pack transport client version - 6.1.2

here is the dependencies and repo i added in my pom as per https://www.elastic.co/guide/en/elasticsearch/reference/6.1/setup-xpack-client.html

<repositories>
        <!-- add the elasticsearch repo -->
        <repository>
            <id>elasticsearch-releases</id>
            <url>https://artifacts.elastic.co/maven</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.elasticsearch.client</groupId>
                <artifactId>x-pack-transport</artifactId>
                <version>6.1.2</version>
                <scope>system</scope>
                <systemPath> /path/to/x-pack-transport.jar</systemPath>
    </dependency>
            <dependency>
                <groupId>org.elasticsearch.plugin</groupId>
                <artifactId>x-pack-api</artifactId>
                <version>6.1.2</version>
                <scope>system</scope>
                <systemPath> /path/to/x-pack-api.jar</systemPath>
            </dependency>
            <dependency>
            <groupId>com.unboundid</groupId>
            <artifactId>unboundid-ldapsdk</artifactId>
            <version>3.2.0</version>
        </dependency>
        <dependency>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bcprov-jdk15on</artifactId>
            <version>1.58</version>
        </dependency>
        <dependency>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bcpkix-jdk15on</artifactId>
            <version>1.58</version>
        </dependency>

I am unable to tag this to X-Pack directly, hence had to tag it to elasticsearch

someone please help

Read this and specifically the "Also be patient" part.

It's fine to answer on your own thread after 2 or 3 days (not including weekends) if you don't have an answer.

I tried to format a bit you post as it was looking weird and was really readable. Please for your next post, make sure that it's correctly formatted (use the preview window to check).

Some thoughts:

  • Why did you manually add bouncycastle lib?
  • What is your Java version.

But more than this, don't use the transport client but the rest client. The transport client will be removed in the future.

Apologies. I will make sure that I follow the guidelines next time.

  • Why did you manually add bouncycastle lib?
    Initially when I ran my application, I got the below error

    Caused by: java.lang.ClassNotFoundException: com.unboundid.util.Debug
    at java.net.URLClassLoader$1.run(URLClassLoader.java:370)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at org.elasticsearch.xpack.XPackPlugin$1.run(XPackPlugin.java:158)

I searched online and implemented the solution given in `this topic . I ran the application after making the above change, now I am getting bouncycastle error

  • What is your Java version.
    1.8

Yes, I plan to move to rest client in next couple of months.

I don't think it's still needed. Unsure though as you are using an old version. You should really move to 6.6.1 Rest Client instead.

Moving to 6.6.1 and Rest Client is a big change and I can't afford to do it right now. Can you please suggest me a fix with out a version upgrade?

I just did. Don't add the other jars than the one recommended in documentation.
If it does not work, then run:

mvn dependency:tree

I am getting the same error even after removing unnecessary dependencies. Please note that when i compile, I don't see any errors and application compiles successfully. Getting this error only when i run the application

    Caused by: java.lang.NoClassDefFoundError: org/bouncycastle/operator/OperatorCreationException
    	at java.lang.Class.getDeclaredConstructors0(Native Method) ~[na:1.8.0_172]
    	at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671) ~[na:1.8.0_172]
    	at java.lang.Class.getConstructors(Class.java:1651) ~[na:1.8.0_172]
    	at org.elasticsearch.plugins.PluginsService.loadPlugin(PluginsService.java:426) ~[elasticsearch-6.1.2.jar:6.1.2]
    	at org.elasticsearch.plugins.PluginsService.<init>(PluginsService.java:105) ~[elasticsearch-6.1.2.jar:6.1.2]
    	at org.elasticsearch.client.transport.TransportClient.newPluginService(TransportClient.java:103) ~[elasticsearch-6.1.2.jar:6.1.2]
    	at org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:128) ~[elasticsearch-6.1.2.jar:6.1.2]
    	at org.elasticsearch.client.transport.TransportClient.<init>(TransportClient.java:262) ~[elasticsearch-6.1.2.jar:6.1.2]
    	at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:128) ~[transport-6.1.2.jar:6.1.2]
    	at org.elasticsearch.xpack.client.PreBuiltXPackTransportClient.<init>(PreBuiltXPackTransportClient.java:58) ~[x-pack-transport-6.1.2.jar:6.1.2]
    	at org.elasticsearch.xpack.client.PreBuiltXPackTransportClient.<init>(PreBuiltXPackTransportClient.java:53) ~[x-pack-transport-6.1.2.jar:6.1.2]
    	at org.elasticsearch.xpack.client.PreBuiltXPackTransportClient.<init>(PreBuiltXPackTransportClient.java:49) ~[x-pack-transport-6.1.2.jar:6.1.2]

Here is the pom file now

<repositories>
        <!-- add the elasticsearch repo -->
        <repository>
            <id>elasticsearch-releases</id>
            <url>https://artifacts.elastic.co/maven</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.elasticsearch.client</groupId>
                <artifactId>x-pack-transport</artifactId>
                <version>6.1.2</version>
                <scope>system</scope>
                <systemPath> /path/to/x-pack-transport.jar</systemPath>
    </dependency>
            <dependency>
                <groupId>org.elasticsearch.plugin</groupId>
                <artifactId>x-pack-api</artifactId>
                <version>6.1.2</version>
                <scope>system</scope>
                <systemPath> /path/to/x-pack-api.jar</systemPath>
            </dependency>
           <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>transport</artifactId>
            <version>6.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>6.1.2</version>
        </dependency>

I ran mvn dependency:tree and here is the output

[INFO] +- org.elasticsearch.client:transport:jar:6.1.2:compile
[INFO] |  +- org.elasticsearch.plugin:transport-netty4-client:jar:6.1.2:compile
[INFO] |  |  +- io.netty:netty-buffer:jar:4.1.13.Final:compile
[INFO] |  |  +- io.netty:netty-codec:jar:4.1.13.Final:compile
[INFO] |  |  +- io.netty:netty-codec-http:jar:4.1.13.Final:compile
[INFO] |  |  +- io.netty:netty-common:jar:4.1.13.Final:compile
[INFO] |  |  +- io.netty:netty-handler:jar:4.1.13.Final:compile
[INFO] |  |  +- io.netty:netty-resolver:jar:4.1.13.Final:compile
[INFO] |  |  \- io.netty:netty-transport:jar:4.1.13.Final:compile
[INFO] |  +- org.elasticsearch.plugin:reindex-client:jar:6.1.2:compile
[INFO] |  |  \- org.elasticsearch.client:elasticsearch-rest-client:jar:6.1.2:compile
[INFO] |  |     +- org.apache.httpcomponents:httpasyncclient:jar:4.1.4:compile
[INFO] |  |     +- org.apache.httpcomponents:httpcore-nio:jar:4.4.5:compile
[INFO] |  |     \- commons-logging:commons-logging:jar:1.1.3:compile
[INFO] |  +- org.elasticsearch.plugin:lang-mustache-client:jar:6.1.2:compile
[INFO] |  |  \- com.github.spullara.mustache.java:compiler:jar:0.9.3:compile
[INFO] |  +- org.elasticsearch.plugin:percolator-client:jar:6.1.2:compile
[INFO] |  \- org.elasticsearch.plugin:parent-join-client:jar:6.1.2:compile
[INFO] +- org.elasticsearch.client:x-pack-transport:jar:6.1.2:system
[INFO] +- org.elasticsearch.plugin:x-pack-api:jar:6.1.2:system
[INFO] +- org.elasticsearch:elasticsearch:jar:6.1.2:compile

Is it the full output of mvn command?

I removed the systempath and scope tags from the pom and tried again. It worked :slight_smile:

I thought we need to manually download the jar and specify the path as it isn't available in maven repository. Turns out that the jars are being fetched from es repo.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.