Loading an automatic module from an exploded directory

Alan Bateman Alan.Bateman at oracle.com
Thu Apr 9 17:35:11 UTC 2020


On 09/04/2020 16:42, Eirik Bjørsnøs wrote:
> The current implementation of automatic modules seems to assume that an
> automatic module is always packaged as a jar file.
>
> I'm working on a module runtime where this is not always the case, and the
> limitation has become a bit of a challenge.
>
> I want to package applications (modules + runtime) at build time into a
> single jar for distribution.
>
> The runtime loads modules from directories within its own jar.  This means
> that ModuleFinder.of(Path..) receives module locations in the form:
>
> jar:file:///path/to/single.jar!/META-INF/modules/module-1.0/
>
> This works fine as long as modules are explicit. (With the unrelated
> limitation that the multi-release feature also seem to assume jar files)
The only packaging format for automatic modules that Java SE defines is 
JAR files. The "Multi-release JAR files" feature is also JAR file only.

If I read your mail correctly, you are creating "multi-module JAR files" 
where the modules are "exploded" under /META-INF/modules in 
${NAME}-${VERSION} directories. It shouldn't be too hard to create your 
own ModuleFinder that finds modules under META-INF/modules. This would 
mean implementing ModuleFinder rather trying to use 
ModuleFinder.of(Path...). I assume you've found ModuleDescriptor.read to 
read/parse the module-info.class of explicit modules. You are right that 
it would require code to scan directory trees, at least the equivalent 
of automatic modules, maybe for explicit modules too. However, it 
shouldn't be too hard. Have you tried the zip file system provider? That 
would allow you to open the JAR file as a file system so you can use the 
file system API.

> :
>
> I have also identify an additional use case which is to allow hot-deploying
> automatic modules during development from target/classes using a Maven
> plugin.
>
I'm not sure how to interpret this but just to say that the unit of 
replacement is the module layer, you can't replace modules in a layer 
and/or dynamically change the set of packages in a loaded module.

-Alan



More information about the jigsaw-dev mailing list