I have two JPMS module in two files: modulea.jar and moduleb.jar. Modulea requires javafx.controls module. I need to use these modules in new layer, so I do:
ModuleFinder finder = ModuleFinder.of(modAPath, modBPath);
ModuleLayer parent = ModuleLayer.boot();
Configuration cf = parent.configuration().resolveAndBind(finder, ModuleFinder.of(), new HashSet<>());
ClassLoader scl = ClassLoader.getSystemClassLoader();
ModuleLayer newLayer = parent.defineModulesWithOneLoader(cf, scl);
I thought that JDK modules will be loaded automatically but I get
Exception in thread "main" java.lang.module.FindException: Module javafx.controls not found, required by modulea
at java.base/java.lang.module.Resolver.findFail(Resolver.java:889)
at java.base/java.lang.module.Resolver.resolve(Resolver.java:191)
at java.base/java.lang.module.Resolver.bind(Resolver.java:297)
at java.base/java.lang.module.Configuration.resolveAndBind(Configuration.java:428)
at java.base/java.lang.module.Configuration.resolveAndBind(Configuration.java:230)
At the same time when I do: java --list-modules, the output is:
...
javafx.base@9
javafx.controls@9
javafx.deploy@9
javafx.fxml@9
javafx.graphics@9
javafx.media@9
javafx.swing@9
javafx.web@9
How to fix it?
requires javafx.controls;in your module-info.java?requires javafx.controls.parentlayer. How else are you trying to access them?javafx.controlsmodule must not be in the boot layer. You can force it into the boot layer by running with--add-modules javafx.controlsbut it would be interesting to know more about the initial module - is this your own launcher/container module that only requires java.base? If so then you may want to run with--add-modules ALL-SYSTEMto ensure that all system modules are in the boot layer as it's unknown what applications it launches might require.javafx.controlsmust not be in boot layer. However, I need it only for this layer, but not for any other layers. How can I add it dynamically to this layer? Answering to your question - in boot layer I have a launcher for other layers which needsjava.base,java.rmiand some others but not anyjavafx.*.