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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With