httpclient jar 冲突。如何解决?
Posted
技术标签:
【中文标题】httpclient jar 冲突。如何解决?【英文标题】:httpclient jar conflicts.How to fix it? 【发布时间】:2016-04-28 12:04:56 【问题描述】://这是我的代码,我正在代理后面工作......
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
我正在使用以下 jars
httpclient-4.5.2.jar
httpcore-4.3.jar
【问题讨论】:
【参考方案1】:SSLContexts
类已重新定位到 httpclient 4.4 中的另一个包。
Since 4.4
将您的 httpcore 版本至少升级到 4.4 以解决该问题。
【讨论】:
【参考方案2】:请看答案 - Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/ConnectionReuseStrategy:。
将 httpcore 版本更新到 4.4。它应该适合你。
【讨论】:
以上是关于httpclient jar 冲突。如何解决?的主要内容,如果未能解决你的问题,请参考以下文章
httpclient.jar和fastjson.jar发生冲突了,怎么解决?两个包都想要