Observable modules

There are two module path values we pass to the javac and java commands--the module source path (passed to javac) containing the uncompiled Java source modules and the module path (passed to javac and  java) containing the compiled Java modules. These options point to the locations of all the modules that are available for the compiler and the runtime to look up and use when necessary. Notice that we didn't have to add the path to the Java platform modules. That's because the Java runtime modules are included by default in the module path for compiling with javac and executing with java. You have to add the path only to the modules that are not a part of the platform, but you intend to include for compilation or execution.

This complete set of modules including modules in the module path that you supply to the platform and the out-of-the-box platform modules that are automatically available are together referred to as observable modules. As the name indicates, these are the modules that the platform observes in order to satisfy module dependencies. If a required module is not among the set of observable modules, the platform complains that the module is missing.

How do you know what the observable modules are? When we've used the java --list-modules command to list the platform modules, what we are actually doing is listing all observable modules. And, by default, only the platform modules are observable. You can also find out what are the observable modules for a given module path. You do that by specifying the --module-path option to the same command. You can specify as value a set of directory locations that form the module path. In that case, the command would display the list of observable modules for that module path, which would include all the platform modules along with any compiled modules in that module path.

For example, if you were to run the command with the module path being the compiled modules in the out folder from the previous chapter (03-two-modules), here's what you'll see:

$ java --module-path out --list-modules
 java.activation@9
java.base@9
java.compiler@9
...
addressbook file:///Users/koushik/code/java9/03-two-
modules/out/addressbook/

sortutil file:///Users/koushik/code/java9/03-two-modules/out/sortutil/

Notice that in addition to the platform modules, there are two of our own modules showing up in the list. This is because they are in the module path we've passed as a parameter to the command, thus adding them to the list of observable modules for that module path. For non-platform modules, the output also includes the path of the module. This makes it handy to locate modules when there are multiple directories passed to the  --module-path option.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.94.190