1

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
4
  • 1
    build path != runtime classpath Commented Aug 15, 2013 at 7:42
  • @JigarJoshi In general, yes, but doesn't Eclipse automatically ensure those JARs are in the runtime classpath when you execute your project? Commented Aug 15, 2013 at 7:43
  • 2
    I don't see eclipse mentioned in whole page (except for your comment, and now in my this comment ) Commented Aug 15, 2013 at 7:44
  • @JigarJoshi I was perhaps reading too much into the use of the buildpath tag, which is exclusive to Eclipse. Commented Aug 15, 2013 at 7:59

2 Answers 2

1

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!

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

2 Comments

Thanks for help. I tried to add commons-codec-1.8.jar, commons-logging-1.1.1.jar, httpclient-4.2.5.jar, httpcore-4.2.4.jar to classpath, but don't work. What should I add to classpath? (I use Eclipse and I used Run/Run Configurations/Classpath.)
@Judit try dumping your runtime classpath System.out.println(System.getProperty("java.class.path")); and see if the jar is available containing class
0

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.

Comments

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.