My application is loading a custom handler class which is outside my applications WEB-INF directory. Now this class which i am trying to load is implenting a public interface(<myinterface> present in a jar file in WEB-INF/lib directory of my application.Am getting this NoClassDefFoundError:<pkg_structure>.<myinterface> while trying to load my custom handler class.
But if i put this custom handler class which i am trying to load inside my WEB-INF its working fine.
Now what could be the problem? Somebody please help me out.This is urgent.TIA.
A web application container typically uses multiple ClassLoaders: one to load common libraries, and one to load each application. I don't know if you know anything about how ClassLoaders work, but they're arranged in a tree, and each ClassLoader can ask its parent ClassLoader to find a class for it, but not the other way around: if a class being loaded by a parent ClassLoader depends on a class only accessible by a child ClassLoader, then the needed class won't be found. That's what's happening here: the individual application ClassLoaders are children of the shared library ClassLoader, and so classes loaded by the shared library ClassLoader can't depend on classes loaded from the individual applications.
So you can either put the "shared" library into your web app, or move the interface into the shared library. Just make sure that the shared library doesn't depend on any classes in the web app.
And don't include duplicate class files in both locations -- then you'll really have problems.