Cui Pengfei 崔鹏飞
Cui Pengfei 崔鹏飞

Reputation: 8305

Running Junit tests in Eclipse, constantly getting "NoClassDefFoundError"

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.

Upvotes: 3

Views: 926

Answers (3)

Cui Pengfei 崔鹏飞
Cui Pengfei 崔鹏飞

Reputation: 8305

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

But I still dont know what when wrong.

Upvotes: 1

Tobias Willig
Tobias Willig

Reputation: 1144

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.

Upvotes: 0

sbridges
sbridges

Reputation: 25150

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.

Upvotes: 2

Related Questions