Which system modules are on the module path by default?
Asked Answered
C

1

11

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.

Colorist answered 18/5, 2017 at 14:56 Comment(0)
P
11

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.

Phipps answered 18/5, 2017 at 16:24 Comment(5)
"The default set of modules enabled in Java 9 are the ones included in the java.se aggregate module" - so why doesn't the runtime fail when I use sun.misc.Unsafe? Unsafe is certainly not in the java.se module graph.Colorist
Good point, the Unsafe class is in the jdk.unsupported module which is required by the java.corba, java.xml.bind, and java.xml.ws modules, so I thought it would only be pulled in if you add one of these modules. Now that I'm re-reading JEP 261, I was missing this part: ". 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." which means that jdk.unsupported would also be a root module by default. Updating my answer nowPhipps
@AndyGuibert The image link is broken in the answer.Epic
@nullpointer thanks for the heads up. I just tested all of the links after reading your comment and they all appear to be working for me. What link is broken for you?Phipps
How can I determine the actual default set of root modules from the command line? Or even better, how can I determine which JRE modules are not in the default set? I am looking for some examples of JRE classes for which I would actually need --add-modules when compiling a non-modular application.Priceless

© 2022 - 2024 — McMap. All rights reserved.