Max
Max

Reputation: 321

Elasticsearch 2.0 NoClassDefFoundError for JsonXContentGenerator

I am trying to update my elasticsearch java client api version from 1.4.2 to 2.0.0. I am using java 1.8 .I use this code:

   XContentBuilder builder = XContentFactory.jsonBuilder()

It used to work in 1.4.2 but I get this exception in 2.0.0:

   Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.elasticsearch.common.xcontent.json.JsonXContentGenerator
   at org.elasticsearch.common.xcontent.json.JsonXContent.newXContentGenerator(JsonXContent.java:69) ~[elasticsearch-2.0.0.jar:2.0.0]
   at org.elasticsearch.common.xcontent.json.JsonXContent.createGenerator(JsonXContent.java:74) ~[elasticsearch-2.0.0.jar:2.0.0]
   at org.elasticsearch.common.xcontent.json.JsonXContent.createGenerator(JsonXContent.java:80) ~[elasticsearch-2.0.0.jar:2.0.0]
   at org.elasticsearch.common.xcontent.XContentBuilder.<init>(XContentBuilder.java:112) ~[elasticsearch-2.0.0.jar:2.0.0]
   at org.elasticsearch.common.xcontent.XContentBuilder.<init>(XContentBuilder.java:102) ~[elasticsearch-2.0.0.jar:2.0.0]
   at org.elasticsearch.common.xcontent.XContentBuilder.builder(XContentBuilder.java:80) ~[elasticsearch-2.0.0.jar:2.0.0]
   at org.elasticsearch.common.xcontent.json.JsonXContent.contentBuilder(JsonXContent.java:40) ~[elasticsearch-2.0.0.jar:2.0.0]
   at org.elasticsearch.common.xcontent.XContentFactory.contentBuilder(XContentFactory.java:122) ~[elasticsearch-2.0.0.jar:2.0.0]
   at org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder(XContentFactory.java:49) ~[elasticsearch-2.0.0.jar:2.0.0]

In pom.xml:

   <dependency>
       <groupId>org.elasticsearch</groupId>
       <artifactId>elasticsearch</artifactId>
       <version>2.0.0</version>
   </dependency>

Upvotes: 3

Views: 7044

Answers (1)

Max
Max

Reputation: 321

The reason is I didnt have com.fasterxml.jackson.core in my dependency list, so this was causing

        java.lang.ClassNotFoundException: com.fasterxml.jackson.core.util.DefaultIndenter

I added this into my pom.xml:

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.6.3</version>
        </dependency>

And problem solved!

Upvotes: 14

Related Questions