Running an Application from a Modular JAR
The adviceApp application can be run from the modular JARs in the mlib directory by any of the following java commands, giving the same output as before:
>
java –module-path mlib –module main
or
>
java –module-path mlib –module main/com.passion.main.Main
The –module-path option (short form: -p) specifies the mlib directory in which to find the modular JARs to run the application. Previously the exploded module directory mods containing the class files for each module was specified.
As seen previously, the –module option (short form: -m) specifies the entry point of the application in the java command. In the first java command, only the module name main is specified. The main module can be found in the main.jar file under the mlib directory by examining the module descriptor in each module on the module path. The main.jar file contains the information about the class with the main() method, as it was specified when the modular JAR for the main module was created—that is, com.passion.main.Main. In the second java command, the entry point is explicitly given, with the module name and the fully qualified class name. Specifying the entry point explicitly overrides the entry point in any modular JAR. However, it makes no difference which command we use in the example above, as there is only one entry point for the application.
We have seen how to create, compile, bundle, and run a modular application. Now we take up the discussion about the remaining directives that can be declared in a module declaration: opening code for reflection (p. 1191) and providing services (p. 1196).
Leave a Reply