In the below example, we can display all modules with classloaders.
Example
import static java.util.Objects.isNull;
public class Java9ClassLoaderTest {
public static void main(String args[]) {
ModuleLayer layer = ModuleLayer.boot();
layer.modules().forEach(module -> {
ClassLoader classLoader = module.getClassLoader();
String classLoaderName = isNull(classLoader) ? "bootstrap" : classLoader.getName();
System.out.println(classLoaderName + ": " + module.getName());
});
}
}
登录后复制
输出
app: jdk.internal.ed
platform: jdk.scripting.nashorn
platform: java.compiler
platform: java.security.jgss
platform: jdk.plugin.dom
bootstrap: jdk.net
bootstrap: java.management
app: jdk.jdeps
platform: javafx.base
app: jdk.editpad
bootstrap: java.security.sasl
platform: java.sql.rowset
bootstrap: java.datatransfer
app: jdk.compiler
platform: java.scripting
platform: jdk.naming.dns
platform: jdk.crypto.mscapi
bootstrap: java.xml
platform: jdk.localedata
platform: javafx.swing
bootstrap: jdk.unsupported
platform: jdk.plugin
bootstrap: jdk.snmp
bootstrap: jdk.naming.rmi
app: jdk.internal.le
platform: javafx.web
platform: jdk.dynalink
platform: jdk.accessibility
bootstrap: java.rmi
platform: jdk.jsobject
platform: java.sql
app: jdk.attach
bootstrap: jdk.management.cmm
platform: jdk.security.auth
platform: java.xml.crypto
bootstrap: jdk.jfr
bootstrap: jdk.management.jfr
platform: jdk.security.jgss
app: jdk.packager.services
bootstrap: java.base
app: jdk.internal.opt
bootstrap: java.prefs
bootstrap: java.management.rmi
platform: jdk.zipfs
platform: java.jnlp
app: jdk.packager
platform: oracle.net
app: jdk.jlink
bootstrap: jdk.management.agent
bootstrap: java.logging
app: jdk.jdi
app: jdk.jstatd
platform: java.se
app: jdk.javadoc
platform: jdk.charsets
platform: java.smartcardio
app: jdk.jconsole
bootstrap: jdk.sctp
platform: javafx.graphics
bootstrap: jdk.management.resource
app: jdk.jdwp.agent
app: jdk.internal.jvmstat
platform: javafx.controls
platform: jdk.crypto.cryptoki
platform: javafx.media
bootstrap: jdk.httpserver
platform: oracle.desktop
bootstrap: java.naming
app: jdk.jshell
app: jdk.jartool
platform: jdk.deploy
bootstrap: java.desktop
platform: javafx.fxml
bootstrap: java.instrument
platform: jdk.crypto.ec
bootstrap: jdk.management
platform: jdk.xml.dom
platform: jdk.javaws
登录后复制
以上就是在Java 9中,我们如何显示所有具有类加载器的模块呢?的详细内容,更多请关注每日运维网(www.mryunwei.com)其它相关文章!