Milen Dyankov
2018-07-30 17:16:17 UTC
In response to a question posted on this list [1] some time ago, Alan
Bateman stated "You can override *any* module (except java.base) with an
alternative implementation in the child layer". Is that true for the
standard JDK modules? If so, is there any documentation / code samples that
explains how?
The obvious naive approach to load standard module in a layer:
ModuleFinder finder = ModuleFinder.ofSystem();
ModuleLayer bootLayer = ModuleLayer.boot();
Configuration cf = bootLayer.configuration().resolve(finder,
ModuleFinder.of(), Set.of("java.sql"));
ClassLoader scl = ClassLoader.getSystemClassLoader();
ModuleLayer layer1 = bootLayer.defineModulesWithOneLoader(cf, scl);
results in
Exception in thread "main" java.lang.LayerInstantiationException: Class
loader (instance of): jdk/internal/loader/Loader tried to define prohibited
package name: java.util.logging
Regards,
Milen
[1]
http://jigsaw-dev.1059479.n5.nabble.com/Whitelisting-modules-in-layers-td5717573.html#a5717574
Bateman stated "You can override *any* module (except java.base) with an
alternative implementation in the child layer". Is that true for the
standard JDK modules? If so, is there any documentation / code samples that
explains how?
The obvious naive approach to load standard module in a layer:
ModuleFinder finder = ModuleFinder.ofSystem();
ModuleLayer bootLayer = ModuleLayer.boot();
Configuration cf = bootLayer.configuration().resolve(finder,
ModuleFinder.of(), Set.of("java.sql"));
ClassLoader scl = ClassLoader.getSystemClassLoader();
ModuleLayer layer1 = bootLayer.defineModulesWithOneLoader(cf, scl);
results in
Exception in thread "main" java.lang.LayerInstantiationException: Class
loader (instance of): jdk/internal/loader/Loader tried to define prohibited
package name: java.util.logging
Regards,
Milen
[1]
http://jigsaw-dev.1059479.n5.nabble.com/Whitelisting-modules-in-layers-td5717573.html#a5717574