5

Why does the following happen and how can I fix it?

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang/Validate
    at org.jsoup.DataUtil.load(DataUtil.java:47)
    at org.jsoup.Jsoup.parse(Jsoup.java:57)
    at linksfind.main(linksfind.java:12)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.Validate
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.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)
    ... 3 more

4 Answers 4

9

This means that the class org.apache.commons.lang.Validate is missing in the runtime classpath. You just have to add the JAR file containing the class to the runtime classpath. It's the Apache Commons Lang JAR file. This is also explicitly mentioned at the current Jsoup download page.

Assuming that you're launching it using plain vanilla java.exe like as in your previous question, then do so:

java -cp .;/path/to/jsoup.jar;/path/to/commons-lang.jar com.example.YourClass

Note that the Jsoup author has mentioned to remove the Commons Lang dependency in the next Jsoup release.

The next release of jsoup will not require Apache Commons-Lang or any other external dependencies, which brings down the jar size to around 115K.

Jsoup 1.3.1 is the first version which does not require Apache Commons Lang anymore.

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

2 Comments

I've just released jsoup 1.3.1 which no longer depends on Apache Commons-Lang (or any other libs).
3

You need to download the Apache Commons/Lang and make sure it's included in CLASSPATH (or if using IDE, make sure that all required libraries are included in the build configuration).

See also

Comments

2

Looks like you need the jar file in your classpath. From google it could be commons-lang-2.4.jar or similar

Comments

1

You can download the Jar from http://mvnrepository.com/artifact/commons-lang/commons-lang/2.4

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.