[jboss-as7-dev] JBOSS MODULES : How to create a new classloader at runtime using existing module + additionnal jars

Philippe Mouawad p.mouawad at ubik-ingenierie.com
Thu Mar 15 05:53:09 EDT 2012


Hello,
I have the following requirement to implement:

   - I have a server that:
      -  creates at runtime new classloaders that must see only parts of
      the server classpath (kind of private ClassLoader):
      - these new classloaders must not see each others

Reading and testing JBoss Modules it seems to me the solution to my issue.
I configured a set of modules and succeeded starting my Server with a
module.

Now I am trying to create dynamically the new classloaders which are
composed of :

   - Server public API
   - Set of JARs embedded in an archive and only visible to the newly
   created ClassLoader

So my idea was to do the following:

   - Create a new Module that would have as dependencies:
      -  the server module (which has only exported a subset of classes)
      - a  set of new JARs

So code would look something like:

        ModuleIdentifier identifier = ModuleIdentifier.fromString("my new
class loader");
        Builder builder = ModuleSpec.build(identifier);
        DependencySpec dependencySpec =
                DependencySpec.createModuleDependencySpec(

ModuleIdentifier.create("com.ubikingenierie.myserver"));
        builder.addDependency(dependencySpec);
builder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(
ResourceLoaders.createJarResourceLoader(
                  "name-of-jar1", new JarFile(new File("path to jar1")))));
builder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(
ResourceLoaders.createJarResourceLoader(
                  "name-of-jar2", new JarFile(new File("path to jar2")))));


        ModuleSpec moduleSpec = builder.create();
...> > What's next ??????


I am stuck here because I don't understand how from this to create the
ClassLoader as I need a Module Loader to build the Module then access
ClassLoader

And the issue is which one ? cause to get access to
"com.ubikingenierie.myserver" I need the root one which I could access like
this:

   - Module mod =
   ((ModuleClassLoader)Thread.currentThread.getContextClassLoaderr()).getModule().getModuleLoader()
   => which is a LocalModuleLoader

But I don't see how to make it load my module , cause If I call loadModule
it won't find ""my new class loader" as it's not in it.


And If I create a new subclass of ModuleLoader I don't see how to make it
use LocalModuleLoader for existing modules.
I looked at ClassifyingModuleLoader which seemed to be a solution but I
don't understand how to use it (no doc , no test case ...)


Anyone can help ?

Thanks

Regards
-- 
Cordialement.
Philippe M.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-as7-dev/attachments/20120315/f1377555/attachment.html 


More information about the jboss-as7-dev mailing list