9

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.

Omid
  • 5,823
  • 4
  • 41
  • 50
ZhekaKozlov
  • 36,558
  • 20
  • 126
  • 155

1 Answers1

10

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.

Andy Guibert
  • 41,446
  • 8
  • 38
  • 61
  • "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. – ZhekaKozlov May 19 '17 at 02:28
  • 2
    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 now – Andy Guibert May 19 '17 at 02:38
  • @AndyGuibert The image link is broken in the answer. – Naman May 25 '17 at 06:30
  • 1
    @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? – Andy Guibert May 25 '17 at 14:54
  • 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. – kriegaex Mar 29 '22 at 04:43