MalcomTucker
MalcomTucker

Reputation: 7477

What can cause java.lang.NoClassDefFoundError?

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

File myFile = new File(FilenameUtils.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.

Upvotes: 5

Views: 7842

Answers (3)

uthark
uthark

Reputation: 5363

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.

Upvotes: 9

Timothy
Timothy

Reputation: 2477

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

Upvotes: 3

Pablo Castilla
Pablo Castilla

Reputation: 2741

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

Upvotes: 2

Related Questions