Meaningless Drivel is fun!*
The moose likes Java in General and the fly likes NoClassDefFoundError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "NoClassDefFoundError" Watch "NoClassDefFoundError" New topic
Author

NoClassDefFoundError

megha sampath
Greenhorn

Joined: Apr 20, 2006
Posts: 3
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.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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.


[Jess in Action][AskingGoodQuestions]
megha sampath
Greenhorn

Joined: Apr 20, 2006
Posts: 3
Thanks a lot for the explanation Ernest.That was really helpful.
 
 
subject: NoClassDefFoundError