tags:

views:

1112

answers:

5

I am getting a NoClassDefFoundError when I run my Java application. How do I fix it?

+1  A: 

This is almost always caused by an incorrect Classpath setting. Make sure the Jar file containing the class Java is complaining about is in the Classpath.

John Meagher
+8  A: 

This is caused when there is a class file that your code depends on and it is present at compile time but not found at runtime. Look for differences in your build time and runtime classpaths.

Mocky
+4  A: 

I have found that sometimes I get a NoClassDefFound error when code is compiled with an incompatible version of the class found at runtime. The specific instance I recall is with the apache axis library. There were actually 2 versions on my runtime classpath and it was picking up the out of date and incompatible version and not the correct one, causing a NoClassDefFound error. This was in a command line app where I was using a command similar to this.

set classpath=%classpath%;axis.jar

I was able to get it to pick up the proper version by using:

set classpath=axis.jar;%classpath%;
shsteimer
+1  A: 

I believe it can also happen if you don't run your java program with the correct syntax. For instance, you have to call your class from the root bin folder with the full package name (ie. my.package.myClass).

I'd be more specific if I could but I'm not much of a java guy. I just remember messing this up a few times.

luckyllama
A: 

Show the line of code where the errors originating from, then we might even tell you what you are missing

svrist