Apache HttpClient throws NoClassDefFoundError

I have: ubuntu-9.10-desktop-amd64 + NetBeans6.7.1

  • I just downloaded "Commons HttpClient 3.1 (legacy)" from http://hc.apache.org/downloads.cgi .
  • I created a new application with NetBeans IDE.
  • I focused on projects -> Libraries -> Add JAR / Folder and added commons-httpclient-3.1.jar here
  • Now I can write "import org.apache.commons.httpclient. *;" This is normal.
  • But if I try to add any expression, include something like this:

    public static void main(String[] args) { HttpClient client = new HttpClient(); } 
  • It is well compiled.

  • But when I run this project, I get the following errors:

     ***Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory at org.apache.commons.httpclient.HttpClient.<clinit>(HttpClient.java:66) at SimplestAppl.Main.main(Main.java:22) Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory at java.net.URLClassLoader$1.run(URLClassLoader.java:217) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:205) at java.lang.ClassLoader.loadClass(ClassLoader.java:319) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294) at java.lang.ClassLoader.loadClass(ClassLoader.java:264) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:332) ... 2 more Java Result: 1*** 

What's wrong?

I tried to download "HttpClient 4.0 (GA)". But the result was the same.

+7
source share
4 answers

What you are experiencing is just a missing addiction. Java developers are used to collect the dependencies themselves, especially. when it comes to registration frameworks. Download commons-logging and add it to your classpath. Also do all the other dependencies required by httpclient.

+14
source

You need dependencies. If you used maven, they would take on themselves. Since you did not do this, you need to go into the system (or possibly others) and drop them.

+5
source

I would like to update anyone coming here to ensure that all the answers, and especially RocketSurgeon, have helped me solve my problem in the same sense. I had to download commons httpclient (legacy 3.1), logging and codec before my problems were resolved.

Also pay attention; using Eclipse, I had to extract the .jar files and import them into the Buildpath using the "add library". Does not work with adding only .zip file.

+2
source

If you do not want to use Maven, then

 - build and launch, look at missing dependencies - identify vendor, fetch the jar to resolve dependencies - rinse/repeat until you have all dependencies satisfied - done 

In any case, you will never be sure that all the dependencies will be 100% delivered. Its usually about 150% or 99%, but never in between

+1
source

All Articles