简体   繁体   中英

java.lang.NoClassDefFoundError: org/apache/http/HttpEntity

Tried everytihng but the solution, I added to buildpath, imported via manifest.mf, but I keep getting this exception. In build path: commons-codec-1.8.jar, commons-logging-1.1.1.jar, httpclient-4.2.5.jar, httpcore-4.2.4.jar. I tried with httpmime-4.0.1 and selenium-server-standalone-2.0b3.jar, but I keep getting this exception.

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/httpEntity
    at autorun.Main.main<Main.java:101>
Caused by: java.lang.ClassNotFoundException: org.apache.http.HttpEntity
    at java.net.URLClassLoader$1.run<Unknown Source>
    at java.net.URLClassLoader$1.run<Unknown Source>
    at java.security.AccesController.doPrivileged<Native Method>
    at java.net.URLClassLoader.findClass<Unknown Source>
    at java.lang.ClassLoader.loadClass<Unknown Source>
    at sun.misc.Launcher$AppClassLoader.loadClass<Unknown Source>
    at java.lang.ClassLoader.loadClass<Unknown Source>
    ... 1 more

Understand the difference between these 2 commands:

  • javac -cp [dir/jar] [class].java
  • java -cp [dir/jar] [class]

Both need the dependencies on classpath, but one needs it for compiling and the other needs it at runtime.Now as per Javadoc:

java.lang.NoClassDefFoundError

Thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.

Which basically means: Everything was okay at compilation/packaging(that is why you have the current Java bytecode!), but at runtime the class(class definition) could not be found.

Now loosely speaking

Build  = compilation + packaging

so buildpath can be thought of as classpath during compilation. The NoClassDefFoundError tells us that the problem occurred at runtime. So that means the required class was present on classpath at compile/build time but was missing at runtime.

Hope it helps!

You need to add the required jars(containing httpEntity and other relevant class ) to your classpath while running your program. Build path is used for compiling /building your code but not for execution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM