Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

httpclient jar conflicts.How to fix it?

//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$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

I am using following jars

httpclient-4.5.2.jar
httpcore-4.3.jar
like image 742
Mohit Mehral Avatar asked Apr 28 '16 12:04

Mohit Mehral


2 Answers

The SSLContexts class has been relocated to another package in httpclient 4.4.

Since 4.4

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

like image 93
Arnaud Avatar answered Oct 22 '22 14:10

Arnaud


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

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

like image 24
asg Avatar answered Oct 22 '22 15:10

asg