Selected Options for the javac Tool
The Java language compiler, javac, compiles Java source code into Java bytecode. The general form of the javac command is:
javac
[options] [sourcefiles]
Table 19.7 shows some selected options that can be used when compiling modules. The optional sourcefiles is an itemized list of source files, often omitted in favor of using module-related options.
Table 19.7 Selected Options for the javac Tool
Option | Description |
–module-source-path moduleSourcePath | The moduleSourcePath specifies the source directory where the exploded modules with the source code files can be found. |
–module-path modulepath -p modulepath | The modulepath specifies where the modules needed by the application can be found. This can be a root directory of the exploded modules with the class files or a root directory where the modular JARs can be found. Multiple directories of modules can be specified, separated by a colon (:) on a Unix-based platform and semicolon (;) on the Windows platform. |
–module moduleName -m moduleName | Specifies the module(s) to be compiled. Can be a single module name or a comma-separated (,) list of module names. For each module specified, all modules it depends on are also compiled, according to the module dependencies. |
-d classesDirectory | Specifies the destination directory for the class files. Mandatory when compiling modules. For classes in a package, their class files are put in a directory hierarchy that reflects the package name, with directories being created as needed. Without the -d option, the class files are put in the same directory as their respective source files. Specifying the directory path is platform dependent: slash (/) on Unix-based platforms and backslash (\) on Windows platforms being used when specifying the directory path. |
–add-modules module,… | Specifies root modules to resolve in addition to the initial modules. These modules can be modular JAR files, JMOD files, or even exploded modules. |
Selected Options for the java Tool
The java tool launches an application—that is, it creates an instance of the JVM in which to run the application. A typical command to launch a modular application is by specifying the location of its modules (path) and the entry point of the application (as module or module/mainclass):
java –module-path
path
–module
module[/mainclass]
Table 19.8 shows some selected options that can be used for launching and exploring modular applications.
Table 19.8 Selected Options for the java Tool
Option | Description |
–module-path modulepath… -p modulepath | The modulepath specifies the location where the modules needed to run the application can be found. This can be a root directory for the exploded modules with the class files or a directory where the modular JARs can be found. Multiple directories of modules can be specified, separated by a colon (:) on a Unix-based platform and semicolon (;) on Windows platforms. |
–module module [/ mainclass ] -m module [/ mainclass ] | When module/mainclass is specified, it explicitly states the module name and the fully qualified name of the class with the main() method, thereby overriding any other entry point in the application. Without the mainclass, the entry point of the application is given by the module which must necessarily contain the main-class. |
–add-modules module,… | Specifies root modules to resolve in addition to the initial modules. |
–list-modules | Only lists the observable modules, and does not launch the application. That is, it lists the modules that the JVM can use when the application is run. |
–describe-module moduleName -d moduleName | Describes a specified module, in particular its module descriptor, but does not launch the application. |
–validate-modules | Validates all modules on the module path to find conflicts and errors within modules. |