Alessandroempire
Alessandroempire

Reputation: 1699

Jsoup error at run time: Exception in thread "main" java.lang.NoClassDefFoundError

I am getting the following error

Exception in thread "main" java.lang.NoClassDefFoundError: org/jsoup/Jsoup
    at Main.main(Main.java:42)
Caused by: java.lang.ClassNotFoundException: org.jsoup.Jsoup
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    ... 1 more

Now what I have done so far:

I created a libs folder in my project folder and added the Jsoup.jar there. Then in eclipse I click properties, add external Jar and added it. I see the referenced library.

But the issue still persist. I dont get compilation errors. So this is a runtime issue. Appreciate the help.

Edit: I have found the following If I compile using

  javac -classpath /path/to/jsoup.jar myclass.java

and then

  java -classpath /path/to/jsoup.jar myclass

It runs perfect. Now. This is not working for me because I am going to use my application on a computer that does not have Jsoup. So how to I resolve this runtime issue?

Upvotes: 1

Views: 2789

Answers (1)

Maxim Kolesnikov
Maxim Kolesnikov

Reputation: 5145

Go to Run configurations... menu and check classpath for Run task. It looks like you add library for Compilation step, but it doesn't set at Run step.

Edit (after comment)

I dove into the issue and found that this dependency is needed for application container. So you just need to add this library to classpath of your app server. If you use Tomcat, just put the library to the %CATALINA_HOME%\lib directory.

Upvotes: 1

Related Questions