Java httpclient jar 冲突。如何解决?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36914117/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 18:48:39  来源:igfitidea点击:

httpclient jar conflicts.How to fix it?

javassljarhttpclient

提问by Mohit Mehral

//This is my code and i am working behind proxy ...

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

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);}

//Following error appears on my console

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

 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.run(Unknown Source)
    at java.net.URLClassLoader.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

I am using following jars

我正在使用以下罐子

httpclient-4.5.2.jar
httpcore-4.3.jar

采纳答案by Arnaud

The SSLContextsclass has been relocated to another package in httpclient 4.4.

SSLContexts班已搬迁到另一个包中的HttpClient 4.4。

Since 4.4

自 4.4

Upgrade your httpcore version to at least 4.4 to fix that.

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

回答by asg

Please take a look at the answer - Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/ConnectionReuseStrategy:.

请看一下答案 -线程“main”中的异常 java.lang.NoClassDefFoundError: org/apache/http/ConnectionReuseStrategy:

Update httpcore version to 4.4. It should work for you.

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