Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which system modules are on the module path by default?

When I run an application via java -cp (without --add-modules or --limit-modules), some Java system modules are observable while the others are not.

For example, all java.se modules are observable. All java.se.ee modules are not observable. I know that javafx.* modules are observable. jdk.unsupported and jdk.shell are observable too.

So, is my assumption correct: if no --add-modules and --limit-modules are specified, the set of observable system modules consists of all system modules except java.se.ee?

Is there a reliable way to know the exact list of default observable system modules? I know there is a --list-modules option, but it lists all modules including java.se.ee.

like image 293
ZhekaKozlov Avatar asked May 18 '17 14:05

ZhekaKozlov


People also ask

What is module path?

A module path is a reference to a module, as used with require or as the initial-module-path in a module form. It can be any of several forms: (quote id) A module path that is a quoted identifier refers to a non-file module declaration using the identifier. This form of module reference makes the most sense in a REPL.

What is module path in Java?

A CLASSPATH is a sequence of classes' base paths and JAR files for the Java Compiler or JVM to locate the classes used in the application. Similarly, in JDK 9, a MODULEPATH is a sequence of modules' base paths and Modular JAR files for the Java Compiler or JVM to locate the modules used in the application.

What is the base module of all the modules in Java 9 is?

java. base is known as the "mother of Java 9 modules." In the following image, you can see the modular aspects of the system and can probably make the leap to understand how a modularized JDK means that you can also modularize your own applications. This is only a few of the 98 platform modules.

What are the different modules in Java?

These modules are split into four major groups: java, javafx, jdk, and Oracle. java modules are the implementation classes for the core SE Language Specification. javafx modules are the FX UI libraries. Anything needed by the JDK itself is kept in the jdk modules.


1 Answers

So, is my assumption correct: if no --add-modules and --limit-modules are specified, the set of observable system modules consists of all system modules except java.se.ee?

In short, yes that is correct.

The default set of modules enabled in Java 9 are known as the root modules. Per JEP 261, the default set of root modules are defined as:

  • The java.se module is a root, if it exists. If it does not exist then every java.* module on the upgrade module path or among the system modules that exports at least one package, without qualification, is a root.

  • Every non-java.* module on the upgrade module path or among the system modules that exports at least one package, without qualification, is also a root.

Here is a nice graphic of what is included in the java.se module: enter image description here (Source: Java 9 javadoc)

Like the java.se aggregate module, the java.se.ee module itself does not provide any classes, it is an aggregate module that includes the following modules:

java.se
java.activation
java.annotations.common
java.corba
java.transaction
java.xml.bind
java.xml.ws

Is there a reliable way to know the exact list of default observable system modules? I know there is a --list-modules option, but it lists all modules including java.se.ee.

Your terminology is slightly off here. In Java 9 a module is observable if both of the following are true:

  • the module is a system module (i.e. comes from the JDK) OR it is added to the module path
  • the module is not excluded via --limit-modules

This means java.se.ee is observable by default.

I think instead you are wondering what modules are the default set of root modules? In which case, see the above definition of root modules.

like image 157
Andy Guibert Avatar answered Sep 21 '22 08:09

Andy Guibert