4

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?

1 Answer 1

9

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.

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks! However, I don't see a JAR under the HttpComponents core "part", only a pom file. I'm not using maven (I tried installing m2Eclipse to get Maven support just for this project but, the learning curve is quite steep.) So do you know which HttpComponents JAR it is that I might be missing?
@glenviewjeff I don't use Maven, but from the page at hc.apache.org/downloads.cgi I see some HttpCore binary downloads you may be interested in.
Ugh, it ends up that all of the Jars are in the zipped "binary" downloads right from Apache's HttpComponents site. Ah, I guess you beat me to it. That was a lot of wasted effort for not bothering to look inside the zips. I don't know what I was thinking was in the "binaries" that led me astray.
@glenviewjeff well, binary as in: bytecode, compiled - as opposed to raw Java source code. Also, I had a look at the pom.xml file you linked to, and it seems that Maven directly downloads HttpComponents Core's source code from the SVN repository at Apache. I feel more comfortable with comprehensive binary downloads from the vendor site.
For future readers--I also had to add the commons-logging-1.1.1.jar to the project to resolve a subsequent error.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.