Hi,
I recently had an idea to try something out and got stuck in my current prototype.
The scenario is the following:
- I got a interface contract for HttpServlets (let's call it IServlet), which implements the Plugin interface
- Next to the contract I got an abstract class (AServlet) which does some basic funcitionality and implements IServlet
- I got another Project with an implementation (CServlet) which extends AServlet
Since Servlet API 3 there it is possible to add servlets in a dynamic way. My plan was to load servlets as plugins and deploy them in my web application.
I am getting a class def not found error when doing a request to one of these servlets.
As far as I understand this correctly, the error appears as follows:
There is a ClassLoader CL1, which is used to load the classes for Tomcat.
The Tomcat itself uses another ClassLoader CL2 to load my web app.
With a initialization servlet I am going to load all the plugins and do some web.xml-alike stuff programatically (naming the servlets, defining fully qualified class names to load them later and do some mapping for http requests).
For this, JSPF does load all the implementations which tell me about there (web-) configuration. everything works fine until here. The debugger shows me correctly loaded plugins.
When I now do some http communication, the server has a lookup which servlet lies behind the path that's requested and tries to initialize a servlet using the fully qual. class name from the loaded config.
That's the moment when the class def not found error is thrown.
I guess, that tomcat tries to instanciate the class in the class loader CL2 but the class is loaded in Class Loader CL3.
If I am wrong, let me know ;)
If I am right, is there a way to tell the Class Loader CL2 to "consume" the classes loaded in Class Loader CL3?
I searched a while and it seems to be possible to do some Code which loads the plugin implementations' using Class Loader CL2, but JSPF does not tell in which file the plugin implementation was found.
What do you think about this idea? Is it possible to load web servlets like this? Is there another strategy I didn't see?
Is there some functionality like PluginManager.loadPlugins(Class<? extends Plugin> contract, ClassLoader target) which I didnt discover yet?
Thanks