Issue
I'm reading through JDK9 release notes and found a small lack of information.
In one of the paragraphs, there is written:
The classes in many non-core modules are now defined to the platform class loader rather than the boot class loader. This may impact code that creates class loaders with null as the parent class loader and assumes that all platform classes are visible to the parent class loader.
Based on this paragraph I tried to find out what are core and non-core modules in Java, but can not find any answer.
I also tried to run a simple program to check classloaders of classes from different modules, but so far sometimes it returned null (which means boot classloader) and sometimes it returned PlatformClassLoader.
I do not want to check all modules manualy. Is there available some list of modules which are considered as core and non-core?
Thank you.
Solution
It is easy to check all modules manually, using ModuleLayer.boot().modules().
For completeness, you should also add the --add-modules=ALL-MODULE-PATH VM option on the command line:
public class ModuleCL {
public static void main(String[] args) {
Map<ClassLoader, Set<Module>> moduleMap = new HashMap<>();
for (var m : ModuleLayer.boot().modules()) {
ClassLoader cl = m.getClassLoader();
Set<Module> modules = moduleMap.computeIfAbsent(cl, __ -> new HashSet<>());
modules.add(m);
}
for (var e : moduleMap.entrySet()) {
System.out.println(e.getKey());
for (var m : e.getValue()) {
System.out.println(" " + m);
}
}
}
}
Which outputs on (my machine) with Java 18:
null
module java.rmi
module java.xml
module java.datatransfer
module jdk.nio.mapmode
module jdk.jfr
module jdk.naming.rmi
module java.naming
module java.management.rmi
module jdk.net
module jdk.management.jfr
module java.management
module java.logging
module jdk.sctp
module java.security.sasl
module jdk.management.agent
module java.instrument
module jdk.unsupported
module java.base
module java.desktop
module java.prefs
module jdk.management
jdk.internal.loader.ClassLoaders$PlatformClassLoader@2f2c9b19
module java.net.http
module java.transaction.xa
module jdk.dynalink
module java.scripting
module jdk.crypto.mscapi
module jdk.crypto.ec
module jdk.localedata
module jdk.security.jgss
module jdk.jsobject
module java.security.jgss
module java.sql.rowset
module jdk.accessibility
module jdk.zipfs
module java.xml.crypto
module java.sql
module jdk.naming.dns
module jdk.charsets
module java.smartcardio
module java.compiler
module jdk.security.auth
module jdk.xml.dom
module jdk.httpserver
module jdk.crypto.cryptoki
jdk.internal.loader.ClassLoaders$AppClassLoader@1d44bcfa
module jdk.attach
module jdk.internal.le
module jdk.jpackage
module jdk.internal.opt
module jdk.jdeps
module jdk.compiler
module jdk.jartool
module jdk.javadoc
module jdk.internal.ed
module jdk.jlink
module jdk.internal.jvmstat
module jdk.editpad
module jdk.random
module jdk.jdwp.agent
module jdk.jshell
module jdk.unsupported.desktop
module jdk.jconsole
module jdk.jstatd
module jdk.jdi
This file defines the mapping of the different modules to the different loaders
Answered By - Johannes Kuhn Answer Checked By - Senaida (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.