jmod - create JMOD files and list the content of existing JMOD files
jmod (create|extract|list|describe|hash) [options] jmod-file
Includes the following:
Main operation modes
Options
Required
Note: For most development tasks, including deploying modules on the module path or publishing them to a Maven repository, continue to package modules in modular JAR files. The jmod tool is intended for modules that have native libraries or other configuration files or for modules that you intend to link, with the jlink tool, to a runtime image.
The JMOD file format lets you aggregate files other than .class files, metadata, and resources. This format is transportable but not executable, which means that you can use it during compile time or link time but not at run time.
Many jmod options involve specifying a path whose contents are copied into the resulting JMOD files. These options copy all the contents of the specified path, including subdirectories and their contents, but exclude files whose names match the pattern specified by the --exclude option.
With the --hash-modules option or the jmod hash command, you can, in each module's descriptor, record hashes of the content of the modules that are allowed to depend upon it, thus "tying" together these modules. This enables a package to be exported to one or more specifically-named modules and to no others through qualified exports. The runtime verifies if the recorded hash of a module matches the one resolved at run time; if not, the runtime returns an error.
See the FileSystem.getPathMatcher method for the syntax of glob-pattern. See the Pattern class for the syntax of regex-pattern, which represents a regular expression.
An options file is a text file that contains the options and values that you would ordinarily enter in a command prompt. Options may appear on one line or on several lines. You may not specify environment variables for path names. You may comment out lines by prefixinga hash symbol (#) to the beginning of the line.
The following is an example of an options file for the jmod command:
#Wed Dec 07 00:40:19 EST 2016 create --class-path mods/com.greetings --module-path mlib --cmds commands --config configfiles --header-files src/h --libs lib --main-class com.greetings.Main --man-pages man --module-version 1.0 --os-arch "x86_x64" --os-name "Mac OS X" --os-version "10.10.5" greetingsmod
In addition to the options described in Options for jmod, the following are extra options that can be used with the command.
The following is an example of creating a JMOD file:
jmod create --class-path mods/com.greetings --cmds commands --config configfiles --header-files src/h --libs lib --main-class com.greetings.Main --man-pages man --module-version 1.0 --os-arch "x86_x64" --os-name "Mac OS X" --os-version "10.10.5" greetingsmod
The following example demonstrates what happens when you try to link a leaf module (in this example, ma) with a required module (mb), and the hash value recorded in the required module doesn't match that of the leaf module.
module ma { requires mb; }
module mb { }
module ma { requires mb; }
module mb { }
jmod hash --dry-run -module-path jmods --hash-modules .*
The command prints the following:
Dry run: mb hashes ma SHA-256 07667d5032004b37b42ec2bb81b46df380cf29e66962a16481ace2e71e74073a
This indicates that the jmod hash command (without the --dry-run option) will record the hash value of the leaf module ma in the module mb.
jmod hash --module-path jmods --hash-modules .*
The command prints the following:
Hashes are recorded in module mb
jmod describe jmods/ma.jmod ma requires mandated java.base requires mb jmod describe jmods/mb.jmod mb requires mandated java.base hashes ma SHA-256 07667d5032004b37b42ec2bb81b46df380cf29e66962a16481ace2e71e74073a
jlink --module-path $JAVA_HOME/jmods:jmods/ma.jmod:../jmodhashex/jmods/mb.jmod --add-modules ma --output ma-app
jlink --module-path %JAVA_HOME%/jmods;jmods/ma.jmod;../jmodhashex/jmods/mb.jmod --add-modules ma --output ma-app
The command prints an error message similar to the following:
Error: Hash of ma (a2d77889b0cb067df02a3abc39b01ac1151966157a68dc4241562c60499150d2) differs to expected hash (07667d5032004b37b42ec2bb81b46df380cf29e66962a16481ace2e71e74073a) recorded in mb