httpclient jar冲突。怎么解决?

时间:2016-04-28 12:04:56

标签: java ssl jar httpclient

//这是我的代码,我在代理后工作......

import org.apache.commons.io.IOUtils;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.DefaultProxyRoutePlanner;

{
HttpHost proxy = new HttpHost("proxyhost", 8082); 
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
HttpClient client = HttpClients.custom().setRoutePlanner(routePlanner).build();
HttpResponse response = client.execute(request);}

//我的控制台上出现以下错误

 Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/ssl/SSLContexts
    at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:966)
    at TwitterFeeds.main(TwitterFeeds.java:40)
    Caused by: java.lang.ClassNotFoundException: org.apache.http.ssl.SSLContexts
    at java.net.URLClassLoader$1.run(Unknown Source)
    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)
    ... 2 more

我正在使用以下广告

httpclient-4.5.2.jar
httpcore-4.3.jar

2 个答案:

答案 0 :(得分:26)

SSLContexts类已重新定位到httpclient 4.4中的另一个包。

Since 4.4

将您的httpcore版本升级至至少4.4以解决此问题。

答案 1 :(得分:3)

请看一下答案 - Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/ConnectionReuseStrategy:

将httpcore版本更新为4.4。它应该适合你。