I can't figure out why I'm getting a ClassNotFoundException here, since I have compiled with the appropriate jar file for WorkUtils, and the class WordUtils is clearly in the jar file.
I compiled with javac -d bin -cp lib/commons-text-1.2.jar MyClass.java
and run with java -cp bin MyClass
Here is my java class:
import org.apache.commons.text.WordUtils;
class MyClass
{
public static void main(String[] args) {
System.out.println(WordUtils.capitalize("sample text"));
}
}
I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/text/WordUtils
at MyClass.main(MyClass.java:11)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.text.WordUtils
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
Anyone know what could be going wrong here?
The library must also be sent to java
:
java -cp bin:lib/commons-text-1.2.jar MyClass
If you're on Windows, you may need to replace :
with ;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With