Running module jar programatically

Alan Bateman Alan.Bateman at
Tue Dec 8 16:26:14 UTC 2015

On 08/12/2015 16:07, Stephane Epardaud wrote:
> OK, so now I have Java 9 + Jigsaw load my module's main method, and in
> there I need to call a class from another module by reflection. That
> other module is in the module path, and I know its name and version. I
> can't use the boot class loader because it's not on the class path (it's
> on the module path).
> Is there somewhere a module registry I can use to add a read to that
> other module and load classes from it?
> Do I have to use a Configuration/Layer to load it? I would think not
> since it's in the module path already, but it could be that it's not
> loaded by the JVM since it's not directly referenced by the main module.
Layer.boot().modules() will give you the set of jlr.Module objects for 
the module in the boot layer but that is probably not what you want.

 From your mail then it sounds like you've got a launcher module m1 and 
wants to load launch an application in another module m2. You'll find a 
jlr.Module for m1 and its transitive dependences in the boot layer but I 
assume not m2 because nobody requires it, is that right?

You could use -addmods m2 for testing purposes to ensure that m2 is 
resolved (in addition to m1).

But it does sounds like you need to create a Configuration to resolve me 
and then create a module Layer. Creating a Configurations requires 
specifying a ModuleFinder to find the modules. You probably don't want 
to have m2 on the application module path, it will instead of on the 
whatever module path option that your launcher takes.


More information about the jigsaw-dev mailing list