Search code examples
solrj

Getting java.lang.NoClassDefFoundError while using solr-solrj-3.6.1.jar


Using Solrj to connect to solr indexes. Used jar solr-solrj-3.6.1.jar which I got by adding below maven dependency

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

I see that CommonsHttpSolrServer is deprecated and hence using HttpSolrServer . During run time i get the below error, Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient

Just adding solr-solrj-3.6.1.jar is not sufficient? Should I have to add more dependencies? I also tried adding httpclient 4.1, It started asking for org/apache/http/HttpRequestInterceptor.


Solution

  • Added below dependencies to get this working

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.2.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpcore</artifactId>
        <version>4.2.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpmime</artifactId>
        <version>4.2.1</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.5.8</version>
    </dependency>
    <dependency>
         <groupId>org.slf4j</groupId>
         <artifactId>slf4j-log4j12</artifactId>
         <version>1.5.8</version>
    </dependency>