[英]java.lang.ClassNotFoundException: org.apache.commons.text.WordUtils
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. 我无法弄清楚为什么我在这里得到一个ClassNotFoundException,因为我已经为WorkUtils编译了相应的jar文件,而且WordUtils类显然是在jar文件中。
I compiled with javac -d bin -cp lib/commons-text-1.2.jar MyClass.java
and run with java -cp bin MyClass
我使用
javac -d bin -cp lib/commons-text-1.2.jar MyClass.java
并使用java -cp bin MyClass
运行java -cp bin MyClass
Here is my java class: 这是我的java类:
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
:
java -cp bin:lib/commons-text-1.2.jar MyClass
If you're on Windows, you may need to replace :
with ;
如果您使用的是Windows,则可能需要替换
:
with ;
If you're using commons-text 1.4+, you have to use Java 8. Make sure you're using the right version of Java; 如果您使用commons-text 1.4+,则必须使用Java 8.确保使用的是正确版本的Java; That was the cause of my
NoClassDefFoundError
. 这是我的
NoClassDefFoundError
的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.