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

跟風遠走 提交于 2019-12-11 14:11:11

问题


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.


回答1:


Add this package to your maven dependencies:

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.2.1</version>
</dependency>



回答2:


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>



回答3:


My simple project of solrj uses the following dependencies:

      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>3.8.1</version>
          <scope>test</scope>
        </dependency>
        <dependency>
          <groupId>org.apache.solr</groupId>
          <artifactId>solr-solrj</artifactId>
          <version>4.4.0</version>
        </dependency>
        <dependency>
          <groupId>org.apache.solr</groupId>
          <artifactId>solr-core</artifactId>
          <version>4.4.0</version>
        </dependency>
        <dependency>
          <groupId>org.apache.commons</groupId>
          <artifactId>commons-logging</artifactId>
          <version>1.1.3</version>
        </dependency>
      </dependencies>

Between, Maven can automatically download them (for example, I started the Java Application of Maven in NetBeans, and then just added the dependencies). Additionally, I needed just to download the library of commons-logging 1.1.3 (http://commons.apache.org/proper/commons-logging/download_logging.cgi). You can read more about libraries and dependencies here: (http://wiki.apache.org/solr/Solrj).



来源:https://stackoverflow.com/questions/12312463/getting-java-lang-noclassdeffounderror-while-using-solr-solrj-3-6-1-jar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!