简体   繁体   English

java.lang.ClassNotFoundException:org.apache.commons.text.WordUtils

[英]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.

相关问题 org.apache.commons.lang.SerializationException:java.lang.ClassNotFoundException - org.apache.commons.lang.SerializationException: java.lang.ClassNotFoundException java.lang.ClassNotFoundException:org.apache.commons.logging.LogFactory - java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory java.lang.ClassNotFoundException:org.apache.commons.dbcp.BasicDataSource - java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource java.lang.ClassNotFoundException:org.apache.commons.collections4.ListValuedMap - java.lang.ClassNotFoundException: org.apache.commons.collections4.ListValuedMap java.lang.ClassNotFoundException:org.apache.commons.fileupload.FileItemFactory - java.lang.ClassNotFoundException: org.apache.commons.fileupload.FileItemFactory java.lang.ClassNotFoundException:org.apache.commons.dbcp2.datasources - java.lang.ClassNotFoundException: org.apache.commons.dbcp2.datasources java.lang.ClassNotFoundException:来自 BaseClassLoader 的 org.apache.commons.lang.StringUtils - java.lang.ClassNotFoundException: org.apache.commons.lang.StringUtils from BaseClassLoader 引起:java.lang.ClassNotFoundException:org.apache.commons.lang3.builder.EqualsBuilder - Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang3.builder.EqualsBuilder java.lang.ClassNotFoundException:org.apache.commons.lang.builder.ToStringBuilder - java.lang.ClassNotFoundException: org.apache.commons.lang.builder.ToStringBuilder java.lang.ClassNotFoundException:运行 apache nutch 时 org.apache.commons.jexl2.JexlContext - java.lang.ClassNotFoundException: org.apache.commons.jexl2.JexlContext while running apache nutch
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM