BigBug
BigBug

Reputation: 6290

Solr new HttpSolrClient.Builder( str ) causing java.lang.NoClassDefFoundError: org/apache/http/impl/client/SystemDefaultHttpClient

Having problems with Sorl. when trying to run the following line of code:

HttpSolrClient solr = new HttpSolrClient.Builder( "http://localhost:8983/solr/core" ).build();

I get the following error: Caused by: java.lang.NoClassDefFoundError:

org/apache/http/impl/client/SystemDefaultHttpClient
    at org.apache.solr.client.solrj.impl.HttpSolrClient.<init>(HttpSolrClient.java:211)
    at org.apache.solr.client.solrj.impl.HttpSolrClient.<init>(HttpSolrClient.java:228)
    at org.apache.solr.client.solrj.impl.HttpSolrClient$Builder.build(HttpSolrClient.java:890)

I read on a couple posts that it could be a dependency issue with Maven since both Swagger and Sorl use httpClient. I moved my dependencies to the same pom and I wrapped dependencies within the dependencymanagement tag.

After doing this I ran the command: mvn dependency:tree -Dverbose

Looking at the tree, it is clear that the duplicate dependency is removed. However, i still get the same error.

Using:

<dependency>
    <groupId>org.apache.solr</groupId>
    <artifactId>solr-solrj</artifactId>
    <version>6.6.0</version>
</dependency>

Any help would be appreciated!

Upvotes: 1

Views: 2592

Answers (1)

John Montgomery
John Montgomery

Reputation: 9058

My guess would be that Swagger is pulling in an earlier version of the library.

It looks like SystemDefaultHttpClient has only existed since version 4.2.

Does mvn dependency:tree -Dverbose show the same versions of http client in both cases?

Upvotes: 3

Related Questions