开发者

What can cause java.lang.NoClassDefFoundError?

开发者 https://www.devze.com 2022-12-19 14:55 出处:网络
My code compiles fine, but I\'m gettting a runtime error on this line: File myFile = new File(FilenameUt开发者_运维百科ils.concat(basePath, localPath));

My code compiles fine, but I'm gettting a runtime error on this line:

File myFile = new File(FilenameUt开发者_运维百科ils.concat(basePath, localPath));

The error thrown is:

java.lang.NoClassDefFoundError: org/apache/commons/io/FilenameUtils

Why would the code compile if it can't resolve a class?

Thanks for any advice.


You should add commons-io library to your runtime classpath.

http://commons.apache.org/io/

In NetBeans Project Properties Window, you click Libraries in the left panel, and in the right panel are 4 categories of classpath you can configure. You should update your Run path or make sure Compile contains commons-io library.


Check this out from the NetBeans tutorial

Basically, you are going to add a JAR file (a library, the commons.apache.org IO one) to your project "properties" classpath.

If you were to run your packaged project from the command line, you could specify classpath like this:

java -cp apache-io.jar myproject.jar


You might have the jar in your developen environment classpath, but you need it in your runtime classpath

0

精彩评论

暂无评论...
验证码 换一张
取 消