简体   繁体   中英

ClassNotFoundException HttpRequestInterceptor

I am getting this weird exception on this line:

HttpSolrServer server = new  HttpSolrServer("http://localhost:8080/solr/");

Stack trace:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/HttpRequestInterceptor
    at com.polgar.dipl.index.SolrIndex.init(SolrIndex.java:36)
    at com.polgar.dipl.index.SolrIndex.getInstance(SolrIndex.java:30)
    at com.polgar.dipl.main.ArticleIndexer.main(ArticleIndexer.java:44)
Caused by: java.lang.ClassNotFoundException: org.apache.http.HttpRequestInterceptor
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 3 more

Getting the same problem. We both must be playing with Solr 3.6

I had to download the HttpClient jars from the HttpComponents project. They didn't seem to be included with Solr 3.6

http://hc.apache.org/downloads.cgi

3.6 Has a new version of the client that uses the new HttpComponents (4.0) stuff, not the old HttpClient (3.1) stuff. The old 3.1 jar is there, but not the new one.

Once I copied the jars over, it worked.

I copied the following (not all may be needed).

httpclient-4.1.3.jar
httpclient-cache-4.1.3.jar
httpcore-4.1.4.jar
httpmime-4.1.3.jar

works for me, now.

If you are using Maven to include SOLRJ, you'll also want the following phrases in your POM:

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

看起来您在运行时类路径中缺少HttpClient Jar文件。

I was also facing this issue. To resolve this, I have done following:

  1. Checked the versions available of http components in your "~.m2\\repository\\org\\apache\\httpcomponents" directory
  2. Based on that add following entries in your pom.xml file and rebuild your project by running mvn clean install and mvn eclipse:eclipse command one by one. (If you are behind the proxy, make sure you have provided essential configuration in your settings.xml file)

This should resolve the problem, It did for me. :)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM