Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoClassDefFoundError with simple Apache HttpClient Eclipse project

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

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

When the test runs, I get the following error:

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

HttpClientDemo is simply:

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?

like image 225
Jeff Axelrod Avatar asked Jan 18 '23 07:01

Jeff Axelrod


1 Answers

Starting from version 4, HttpClient has been split in three parts, under the HttpComponents moniker: Core, the proper Client, and an AsyncClient. The HttpParams class is now part of HttpComponents Core, so you will also need the specific JAR for that component (supposedly named httpcore-4.1.3.jar) in order to successfully compile your simple example.

like image 92
Giulio Piancastelli Avatar answered Feb 09 '23 06:02

Giulio Piancastelli