NoClassDefFoundError with a simple Apache HttpClient Eclipse project

I am trying to create a simple Eclipse project to test my code that uses HttpClient code.

I created a simple Java project in Eclipse, added a Junit4 test case (code below.) I added httpclient-4.1.3.jar to the Eclipse project, which I manually downloaded from Maven Central here and added the jar to the Java build path.

When the test passes, I get the following error:

java.lang.NoClassDefFoundError: org/apache/http/params/HttpParams at HttpClientDemo.test(HttpClientDemo.java:13)

HttpClientDemo is simple:

 import org.apache.http.client.HttpClient; import org.apache.http.impl.client.DefaultHttpClient; import org.junit.Test; public class HttpClientDemo { @Test public void test() { HttpClient httpclient = new DefaultHttpClient(); } } 

Why am I getting this error?

+4
source share
1 answer

Starting with version 4, HttpClient has been divided into three parts under HttpComponents : Core, the correct client, and AsyncClient. The HttpParams class HttpParams now part of the HttpComponents core, so to successfully compile your simple example, you will also need a specific JAR for this component (presumably with the name httpcore-4.1.3.jar ).

+9
source

Source: https://habr.com/ru/post/1400294/


All Articles