Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting "java.lang.NoClassDefFoundError: org/apache/http/nio/reactor/IOReactorException"

I'm trying to use a Mashape api, I have added the following libraries (jars) unirest, httpasyncclient, httpclient, httpmime, org.json, commons-longging, httpcore to my project.

I'm trying to run...

HttpResponse<JsonNode> response = Unirest.post("https://life-left.p.mashape.com/time-left")
.header("X-Mashape-Key", "1NZITOdDGqmshKRAEdDbX0tp0WV2p1RR5SSjsnQYQIVwrANkhC")
.header("Content-Type", "application/x-www-form-urlencoded")
.field("birth", "22 April 1977")
.field("gender", "female")
.asJson();

But I get this exception...

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/nio/reactor/IOReactorException
at com.mashape.unirest.http.HttpClientHelper.prepareRequest(HttpClientHelper.java:154)
at com.mashape.unirest.http.HttpClientHelper.request(HttpClientHelper.java:131)
at com.mashape.unirest.request.BaseRequest.asJson(BaseRequest.java:68)
at test.Test.main(Test.java:24)
Caused by: java.lang.ClassNotFoundException: org.apache.http.nio.reactor.IOReactorException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)

I've tried googling around but I can't find out what is wrong.

Any help would be appreciated.

like image 611
OneTwo Avatar asked Nov 03 '14 12:11

OneTwo


1 Answers

I had same problem but resolved after adding following dependency in my project pom.xml file

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpcore-nio</artifactId>
        <version>4.4.3</version>
    </dependency>
like image 170
Dharmesh Gohil Avatar answered Sep 29 '22 09:09

Dharmesh Gohil