views:

32

answers:

2

Project A depends on project B.

On compilation time , everything is OK.

On debug , when a static function from class bClass of project B is called , I get NoClassDefFoundError .

On run , I get ExceptionInInitializerError.

Besides , the bClass has a static initializer , and when I put a break point there , it never reaches it - which seems very strange to me , but also makes sense because the class is probably not found.

Any idea how to fix? I've checked all dependencies to the best of my understanding.

A: 

I've often found that if a static initializer throws an exception, then you get these sorts of confusing and misleading results. Try this: Put a try/catch statement around all of the code that is in the static initializer, and in the catch block, log the exception (in the error log or to the console). If there is an exception that's being thrown, this will help you narrow it down.

static {
    try {
        // ... your code here ...
    } catch (Throwable t) {
        t.printStackTrace();
    }
}

When you're done debugging, you should remove this try/catch clause, because it swallows the exception.

Mike Morearty
+1  A: 

In the case of NoClassDefFound exceptions, double check your runtime classpath against your compiletime classpath. Eclipse usually uses the compile-time classpath for the runtime CP but if you have modified the default launch config, they may not match anymore.

Kelly French