Selected Options for the jar Tool
The jar tool is an archiving and compression tool that can be used to bundle Java artifacts and any other resources that comprise the application. The archive file names have the .jar extension. A typical command to create a modular JAR (jarfile) with an application entry point (qualifiedMainClassName), based on the contents of a specific directory (DIR), is shown below. Note the obligatory dot (.) at the end of the command.
jar –create –file
jarfile
–main-class
qualifiedMainClassName
-C
DIR
.
Table 19.9 gives an overview of some selected options that can be used for working with JARs.
Table 19.9 Selected Options for the jar Tool
Option | Description |
–create or -c | Creates a new archive. |
–extract or -x | Extracts specified or all files in the archive. |
–list or -t | Lists the contents of the archive. |
–update or -u | Updates an existing archive with specified files. |
–describe-module or -d | Prints the module descriptor of the archive and the main-class, if one is specified in the manifest. |
–verbose or -v | Prints extra information about the operation. |
–file jarfile –file= jarfile -f jarfile -f= jarfile | Specifies the name of the archive. |
-C DIR files | Changes to the specified directory and includes the contents of the specified files from this directory. If files is a dot (.), the contents under the specified directory DIR are included. |
Click here to view code image –main-class qualifiedMainClassName –main-class= qualifiedMainClassName -e qualifiedMainClassName -e= qualifiedMainClassName | Specifies the entry point of the application. |
–manifest TXTFILE –manifest= TXTFILE -m TXTFILE -m= TXTFILE | Reads the manifest information for the archive from the specified TXTFILE and incorporates it in the archive—for example, the value of the Main-Class attribute that specifies the entry point of the application. |
–module-path modulepath -p modulepath | Specifies the location of the modules for recording hashes. |
Selected Options for the jdeps Tool
The Java Class Dependency Analyzer, jdeps, is the tool of choice when working with modules, as it is module savvy and highly versatile. Among its extensive module analyzing capabilities, it can be used to explore dependencies at different levels: module level, package level, and class level.
Table 19.10 gives an overview of some selected options for the jdeps tool that can be used for analyzing modules.
Table 19.10 Selected Options for the jdeps Tool
Option | Description |
–module-path modulepath | Specifies where to find the module JARs needed by the application. No short form, as -p is already reserved for –package. |
–module-name moduleName -m moduleName | Specifies the root module for module dependency analysis. |
-summary or -s | Presents only a summary of the module dependencies. |
–recursive or -R | Forces jdeps to recursively iterate over the module dependencies. When used alone, also prints the package-level dependencies. |
-verbose or -v | Also includes all class-level dependencies in the printout. |
-verbose:package | Includes package-level dependencies in the printout, excluding, by default, dependencies within the same package. |
-verbose:class | Includes class-level dependencies in the printout, excluding, by default, dependencies within the same JAR. |