On 05/02/2021 15:39, Gunnar Morling wrote:
Hi all,
While working on Layrry [1] [2] [3], a launcher and runtime for
layered Java applications, I've come to wonder whether there's a way
for sourcing multiple module layers from a custom runtime image
created via jlink?
I couldn't find a way so far, as a) it seems not possible to add
multiple versions of a module to a runtime image (one of the use cases
for layered applications), and b) it's not clear how the module finder
API would address modules in an image. If this is not supported atm.,
are there any plans to do so?
To give some context on Layrry, it's an exploration for providing a
framework that allows the creation of modularized applications based
on the module system and its notion of layers, addressing the
multi-version issue of (transitive) dependences, provisioning modules
based on their Maven coordinates, supporting the dynamic
addition/removal of layers at runtime ("plug-ins"), and more.
No, there isn't any support for this.
As things stand, the universe of observable modules at startup includes
all modules in the run-time image. If a run-time image were to include
modules only intended for module layers created at run-time then there
would need to be configuration or something to support the partitioning,
also maybe APIs to expose enough at run-time to reconstitute the
configuration. There would be restrictions on the content of these
modules, e.g. modules intended only for child layers couldn't contribute
command-line launchers for the bin directory. The container format used
for classes and resources would need to be rev'ed to support more
complex addressing (this is something we explored a bit in JDK 9 but
didn't go too far), or the run-time image structure would need to be
updated to support directories of observable modules for each
configuration. A lot of complexity would be heaped on jlink as it would
have to create the configuration for each of the layers at link time,
maybe even a training run to map the modules to class loaders to
identity consistency issues at link-time. Overall I think it would add a
lot of complexity in many areas.
Module layers are great for containers that launch applications that use
different versions of components, it's also great for plugins and
dynamic behavior (the "Finding Plug-In Implementations ..." section in
your blog is good). I'm less sure about trying to bring it to the link
phase where it's about static configuration and link-time optimizations.
-Alan