question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

POST throw java.lang.ClassNotFoundException: org.apache.http.HttpEntity

See original GitHub issue

EDIT: java version "1.8.0_74"

I have a private Maven repository and uploaded the artifacts for Unirest, org.json, httpclient, httpmime, httpasyncclient.

My dependencies on the pom.xml is exactly like the example on the homepage:

    <dependencies>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.3.6</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpasyncclient</artifactId>
            <version>4.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpmime</artifactId>
            <version>4.3.6</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20140107</version>
        </dependency>
        <dependency>
            <groupId>com.mashape.unirest</groupId>
            <artifactId>unirest-java</artifactId>
            <version>1.4.9</version>
        </dependency>
    </dependencies>

This is the code I inserted on my Main.java

import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;

public class Main {
    public static void main(String[] args) throws UnirestException {
        HttpResponse<JsonNode> jsonResponse = Unirest.post("http://httpbin.org/post")
                .header("accept", "application/json")
                .queryString("apiKey", "123")
                .field("parameter", "value")
                .field("foo", "bar")
                .asJson();
        System.out.println(jsonResponse.getBody().toString());
    }
}

When I run the code this is the output:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/HttpEntity
	at com.mashape.unirest.request.HttpRequestWithBody.field(HttpRequestWithBody.java:102)
	at com.mashape.unirest.request.HttpRequestWithBody.field(HttpRequestWithBody.java:94)
	at Main.main(Main.java:12)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.ClassNotFoundException: org.apache.http.HttpEntity
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 8 more

With my IDE (Intellij IDEA Community) I have looked into the package org.apache.http from httpclient-4.3.6.jar jdoes not contain any HttpEntity class.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8

github_iconTop GitHub Comments

10reactions
MiladAlshomarycommented, Apr 27, 2017

@poliveira89

I have struggled for an hour collecting the dependencies to get this library to run! Here are the list of jars needed to make it run:

unirest-java-1.4.9.jar httpasyncclient-4.0.2.jar httpclient-4.3.6.jar httpmime-4.3.6.jar json-20140107.jar httpcore-4.3.jar org-apache-commons-logging.jar httpcore-nio-4.3-beta2.jar

6reactions
MiladAlshomarycommented, Apr 28, 2017

These two jars needed to fulfill the dependencies! Though they are not mentioned in the documentation. It seems that they updated the code but they didn’t update the documentation!

Read more comments on GitHub >

github_iconTop Results From Across the Web

java.lang.NoClassDefFoundError: org/apache/http/HttpEntity
The ClassLoader can't find org.apache.http.HttpEntity, which should be inside "httpcore-4.3.jar". Open the jar as an archive and verify that it contains ...
Read more >
java.lang.ClassNotFoundException: org.apache.http.HttpEntity
BloodDonorProfileBean) throws java.lang.Exception' threw an unexpected exception: java.lang.NoClassDefFoundError: org/apache/http/HttpEntity.
Read more >
java.lang.NoClassDefFoundError: org/apache/http/client ...
I am trying to make a get request from the GWT servlet to get JSON response from a web service. Following is the...
Read more >
JR63529: CLASSNOTFOUNDEXCEPTION OCCURS WHEN ...
When you import a snapshot from a twx file, it fails and the following exception is logged in the SystemOut.log:
Read more >
How to fix java.lang. ClassNotFoundException: org ... - Crunchify
... org.springframework.web.servlet.DispatcherServlet Exception – Spring MVC, Tomcat and 404 Error. Last Updated on May 28th, 2021 by App Shah 36 comments.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found