You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何出现java.lang.ClassNotFoundException: org.apache.commons.text.WordUtils?

Fixing ClassNotFoundException for WordUtils

The issue here is straightforward—your run command is missing the commons-text jar from the classpath.

When you compiled with javac -d bin -cp lib/commons-text-1.2.jar MyClass.java, you told the compiler where to find the WordUtils class to validate your code. But when you run the program, the JVM needs access to that same jar file to actually load the WordUtils class at runtime. Without including it in the runtime classpath, the JVM can't locate the class, hence the ClassNotFoundException.

Corrected Run Command

On Linux/macOS:

java -cp bin:lib/commons-text-1.2.jar MyClass

On Windows:

java -cp bin;lib/commons-text-1.2.jar MyClass

(Note: Use : as the classpath separator on Unix-like systems, and ; on Windows.)

Bonus Tip

If you have multiple jars in the lib directory, you can use a wildcard to include all of them instead of listing each one:
Linux/macOS:

java -cp bin:lib/* MyClass

Windows:

java -cp bin;lib/* MyClass

内容的提问来源于stack exchange,提问作者spectrum

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 07:48:19