ElasticSearch SearchRequestBuilder java.lang.NoClassDefFoundError: com.fasterxml.jackson.core.JsonGenerator


(Raaj Mandal) #1

I am using ElasticSearch 2.1.1 version. Using a java client I am trying to execute a search request.

SearchResponse searchResp = 
client.prepareSearch(index)
.setTypes(type)
.setQuery(QueryBuilders.matchQuery("field", "value"))
.setFetchSource(new String[]{"selected"}, null)
.execute()
.actionGet();

I am using Jackson as my JSON library. here are my pom.xml entries

<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.6.0</version>
<scope>provided</scope>
    </dependency>

    <dependency>
    <groupId>com.fasterxml.jackson.jaxrs</groupId>
    <artifactId>jackson-jaxrs-xml-provider</artifactId>
    <version>2.6.0</version>
    <scope>provided</scope>
    </dependency>

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

    <dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.6.0</version>
    <scope>provided</scope>
</dependency>

     <dependency>
    <groupId>org.elasticsearch</groupId>
    <artifactId>elasticsearch</artifactId>
    <version>2.1.1</version>
    <scope>provided</scope>
     </dependency>

I have deployed the application is Websphere Application Server, and have included the Jackson libraries in a sharedlib(isolated classloader)

the above code is throwing the exception

com.ibm.ws.webcontainer.webapp.WebApp logServletError SRVE0293E: [Servlet Error]-[UserGroupsManagementApplication]: **java.lang.NoClassDefFoundError: com.fasterxml.jackson.core.JsonGenerator**
    at java.lang.J9VMInternals.verifyImpl(Native Method)
    at java.lang.J9VMInternals.verify(J9VMInternals.java:94)
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:169)
    at org.elasticsearch.common.xcontent.XContentFactory.contentBuilder(XContentFactory.java:124)
    at org.elasticsearch.action.support.ToXContentToBytes.buildAsBytes(ToXContentToBytes.java:62)
    at org.elasticsearch.action.search.SearchRequest.source(SearchRequest.java:250)
    at org.elasticsearch.action.search.SearchRequestBuilder.beforeExecute(SearchRequestBuilder.java:1019)
    at org.elasticsearch.action.search.SearchRequestBuilder.beforeExecute(SearchRequestBuilder.java:50)
    at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:85)
    at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:59)

By doing a type search in eclipse for JSONGenerator, I can see that this class is also available in jackson-core-asl-1.9.2.jar (codehaus package). This dependency is being automatically added by maven.

I am not sure if this is a conflict issue. Please help.


(Jason Tedor) #2

Yes, it's almost surely a JAR hell issue that you'll need to resolve. A NoClassDefFoundError usually has a root cause that will give you more insight into the exact problem here (I would guess it's a class initialization failure) but either way you're going to have get around the JAR hell.


(system) #3