On 08/10/2025 06:19, Jaroslav Tulach wrote:
Dear JPMS experts!
I am currently working at Enso developing runtime for _dual representation
(visual and textual) programming language_
[Enso](https://urldefense.com/v3/__https://github.com/enso-org/__;!!ACWV5N9M2RV99hQ!MSZoD63gQltbiD0s6RtcgnXj1LJG0hqBQb84MygtZ7LKRGpELc0ZURO2QOh0lZjT8PhyJ4QCjYOv2G3AvcdF32JDTpk$
enso/). Enso uses JVM for its operating system interoperability - as such we
are packaging our runtime, as well as Enso libraries as modular JAR files.
Basically we need a _modular runtime container_ with JPMS...
And here comes the question: Is there a way to create `ModuleLayer` for just
`java.base`?
Enso runtime obviously needs many other JDK & co. modules. However I don't
want to expose them to the Enso library module JARs (possibly coming from 3rd
party sources) - I'd like them to use only `java.base` and not randomly poke
around for other Enso runtime module JAR files.
Is there a way to do it? I failed to find it. Googling it out yields no
relevant results and I don't like the idea of chatting with an AI. I'd rather
talk to the experts - hence I am writing to you!
- I can get `ModuleLayer.boot()` - but that contains too many modules - for
example `org.enso.runner` & co. which I' do not want to expose
- I can get `ModuleLayer.empty()` - but that one is a bit "too empty"
- I tried to create own layer with `ModuleLayer.empty()` as parent and put
`ModuleFinder.ofSystem()` and `java.base` module in...
- but I am getting various errors related to classloaders - "java.base must
be loaded by system classloader" - etc.
- in short: I haven't found a way to get thru and construct `java.base` only
layer
How that is supposed to work? How do I create a `ModuleLayer` with just
`java.base` and control what the Enso library JARs can access? Can I control
that regardless of how the JVM was initialized? There must a a way, right? Or
am I asking for too much encapsulation?
I think what you are looking for is to create the Configuration for a
child layer in a way that "hides" all but java.base from the modules in
the parent configuration. There isn't a way to do this as resolution
time. That is, if the configuration for the parent/boot has java.base,
enso, and apache.foo (used by enso) then there is no way to have
resolution fail if a user module requires enso or requires apache.foo.
Who creates the configuration for the child layer? Can it process the
Configuration and fail if any module in the configurations reads a
module other than java.base?
-Alan