NoClassDefFoundError
I am u开发者_StackOverflow社区sing eclipse to develop my application. In my application i have few projects and those projects have reference in EAR project.
In one of project i have created a interface and impementation for that interface.
I am trying to craete object for that class
MyInterface myObj = new MyClass();
It was not working so i started server in debug mode. I am getting NoClassDefFoundError
.
Any idea why i am getting this error. I have already added new project in my project build path. If i write
MyInterface myObj = null;
i do not get any error.
Check the classpath used by the runtime configuration you're running in Eclipse, which is normally defined by the project libraries and source folders.
Since you're working with an EAR, you probably use an app server, and you need to know that most of them work with one parent classloader and a child classloader per ear or war. That means that if a class loaded by a parent classloader tries to instantiate a class which is only in a child classloader you get a NoClassDefinedError (the other way around you don't).
This was happening to me. The problem was not that "MyClass" was missing from the classpath. What was missing in my case was one of the dependencies inside MyClass (i.e. an import) and when the constructor was called it failed.
Check my related question and the answer: Class Constructor fails throwing Exception on Class Loading as well as the question before that which is when all my problems started: Weird behavior with Constructor and Class. Application hangs `forever` on Constructor
精彩评论