Classes using different ClassLoaders can't see each other; NoDefClassFound
Hi all,
In working on a plugin engine that dynamically loads classes, we figured (from various resources) that each plugin should have its own class loader. This way, we can unload a class properly at runtime, and hopefully even reload it. All plugins would be outside of the JVM classpath. Each plugin has a new URLClassLoader created for it. For the most part, this seems to work. Where we are running into problems is when a client using our engine wants to use a "service" a plugin adds. We keep seeing NoDefClassFound exceptions. If we put the .class file in the client classpath, it works. But usually a plugin would be a self contained bit of code. It may rely on other code (via its import statements). We take care of this by allowing the engine to contain a list of all plugin services. Then, plugins can look them up, getting references back to the implementing classes from various plugins. It seems though that this also doesn't work.
The goal is for me to be able to develop a completely self contained plugin, package it in a JAR file (which our engine reads from JAR files for plugins), and allow the application/engine to load them for use. Each plugin can (but is not required to) add a service. Basically, an interface that extends our Service interface. Other plugins do a lookup through the engine and when found, get a reference back. This seems to work fine if all plugins are loaded via the same class loader.
The problem seems to be that if a plugin that uses another plugin does NOT contain that plugins .class files within the reach of the new classloader instance that loads it, it can not use it.
I would love to know if there are any sites that more thoroughly explain how class loaders work when trying to use other classes, and perhaps find a better solution to our problem than requiring all .class files that are used by a specific plugin to be packaged with it. If that is the only solution, then we will go with it, but I was hoping there was a way to avoid having to have each plugin package other plugins .class interfaces with it just to use them. Although, this is how EJB does it with requiring client classes to use the home/remote interfaces of an EJB.
Lastly, I have seen that some app servers are able to reload servlets and what not. Not sure if this is done in the same manner we are after. I know if a classloader loads all the servlets, all servlets would have to be reloaded for this to work properly. But app servers like Resin, Orion and even JBoss can "hot-deploy" by unloading and reloading specific classes.
Thanks for any help.

