Multi-Module Compilation
It is tedious compiling modules individually. It is more convenient to use the following command:
>
javac –module-source-path src -d mods –module main
The –module-source-path option (no short form), as the name suggests, indicates the src directory where the exploded modules with the source files for the modules can be found.
The -d option (no short form) indicates the directory mods for the exploded modules with the class files. The compiler creates the module root directories and the package hierarchies as necessary under the mods directory.
The –module option (short form: -m) can be used to specify the name of a single module or a list of module names separated by a comma (,) with no intervening space characters. For each module specified, the compiler will only compile those modules that this module depends on. The compiler does the necessary module dependency analysis and compiles all the modules in the right order. If only the model module had been specified, only it will be compiled, as it does not depend on any other module.
The result of the above command is the same as before, shown in Figure 19.14(a).
Running a Modular Application from Exploded Modules
Typically, the java command needs to know where to find the modules needed to run the application and also the entry point of the application, meaning the class whose main() method should be executed to launch the application.
>
java –module-path mods –module main/com.passion.main.Main
See no evil.
Speak no evil.
Hear no evil.
No advice.
The –module-path option (short form: -p) is used to specify where to find the modules needed to run the application. In this case it is the mods directory containing the exploded modules with the class files. This option can also specify a colon-separated (:) list of directories (semicolon (;) separated in Windows) to look up the required modules.
The –module option (short form: -m) in the command explicitly specifies the entry point of the application. In this case, it is the class Main in the com.passion.main package of the main module that provides the main() method. This requires the fully qualified name of the class (com.passion.main.Main) and the full name of the module (main). Note the directory-level separator (/) in the specification of the entry point.
Leave a Reply