2016-04-28 56 views
8

//這是我的代碼和我工作背後的代理...我的控制檯上顯示httpclient jar衝突。如何解決?

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 

回答

16

SSLContexts類已被重定位到httpclient 4.4中的另一個包。

Since 4.4

升級您的HttpCore版本至少4.4修理好了。