Take the 2-minute tour ×

I added a new test class. And tried to run it, but got the no class def found error. But other test classes work fine. And I am sure the new test class is compiled, its .class file is in the right folder.

share|improve this question
Can you post more details please ? Like Junit test and etc.? and how are you running it ? –  Big Show Sep 7 '12 at 3:42
@Anuj Kulkarni I am running it using alt+shift+ x,t. Using Junit 4 –  CuiPengFei Sep 7 '12 at 4:15
add comment

3 Answers

There isn't enough information in the question to provide a real answer.

The first step to debugging is to see if the .class file is really on the classpath, do something like,

Class c = SomeClass.class;
System.out.println(c.getResource(c.getSimpleName() + ".class"));

If you print something non null, then the .class file is on the classpath.

The second step is to make sure the NoClassDefFoundError is really being caused because the class you are loading does not exist. Use an eclipse exception breakpoint to break on NoClassDefFoundError, and see what class it is really trying to load. It may be that class X requires class Y to load.

share|improve this answer
thanks, i'll try that. –  CuiPengFei Sep 7 '12 at 4:16
add comment
up vote 1 down vote accepted

problem solved by right clicking the project and then select maven->update project configurations.

But I still dont know what when wrong.

share|improve this answer
Thanks, that's nailed it for me too.. –  HaveAGuess Dec 16 '12 at 22:23
I think the issue for me was I tried to get eclipse building into its own folder outside of target but the m2e plugin is taking over junit runs and using its classpath rather than your eclipse one –  HaveAGuess Dec 16 '12 at 22:25
add comment

You get a NoClassDefFoundError if a class file was present at compile time, but is not available at runtime. So my recommendation is to check your class path, maybe a library or something else is missing for the new test.

share|improve this answer
add comment

Your Answer


