JMOD(1)

πŸ’… bestie, meet jmod β€” straight from the JDK Commands manual (JMOD(1)) πŸ’…

okay so real talk: this is the jmod page, and she is very specific but very iconic. We're talking create JMOD files, list what's inside existing ones, and generally do build-time main character things. Let's go πŸ’–

✨ NAME ✨

jmod β€” create JMOD files and list the content of existing JMOD files. that's the name, no cap πŸ’…

🌸 SYNOPSIS 🌸

jmod (create|extract|list|describe|hash) [options] jmod-file

Includes the following:

πŸŽ€ Main operation modes πŸŽ€

  • create β€” Creates a new JMOD archive file. fresh archive, who dis? ✨
  • extract β€” Extracts all the files from the JMOD archive file. unzip vibes.
  • list β€” Prints the names of all the entries. the cast list, basically.
  • describe β€” Prints the module details. spill the tea.
  • hash β€” Determines leaf modules and records the hashes of the dependencies that directly and indirectly require them. cryptographic tying, but make it fashion.

🫢 Options 🫢

options β€” See Options for jmod.

πŸ’œ Required πŸ’œ

jmod-file β€” Specifies the name of the JMOD file to create or from which to retrieve information.

πŸ¦‹ DESCRIPTION πŸ¦‹

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 you can use it during compile time or link time but not at run time. so no, you can't just yeet it and run it, bestie 😭

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. ok so it's giving copy-paste but with a bouncer at the door πŸšͺ✨

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. so if the hash doesn't match, it's a whole error moment πŸ’€

πŸ”₯ OPTIONS FOR JMOD πŸ”₯

okay bestie, here comes the whole flag parade. every single one is getting her moment πŸ’–

  • --class-path path β€” Specifies the location of application JAR files or a directory containing classes to copy into the resulting JMOD file.
  • --cmds path β€” Specifies the location of native commands to copy into the resulting JMOD file.
  • --compress compress β€” Specifies the compression to use in creating the JMOD file. The accepted values are zip-[0-9], where zip-0 provides no compression, and zip-9 provides the best compression. Default is zip-6.
  • --config path β€” Specifies the location of user-editable configuration files to copy into the resulting JMOD file.
  • --dateTIMESTAMP β€” The timestamp in ISO-8601 extended offset date-time with optional time-zone format, to use for the timestamp of the entries, e.g. "2022-02-12T12:30:00-05:00". This is exactly how the option is printed here, bestie β€” the create examples below use --date.
  • --dir path β€” Specifies the location where jmod puts extracted files from the specified JMOD archive.
  • --dry-run β€” Performs a dry run of hash mode. It identifies leaf modules and their required modules without recording any hash values.
  • --exclude pattern-list β€” Excludes files matching the supplied comma-separated pattern list, each element using one of the following forms:
    • glob-pattern
    • glob:glob-pattern
    • regex:regex-pattern

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.

  • --hash-modules regex-pattern β€” Determines the leaf modules and records the hashes of the dependencies directly and indirectly requiring them, based on the module graph of the modules matching the given regex-pattern. The hashes are recorded in the JMOD archive file being created, or a JMOD archive or modular JAR on the module path specified by the jmod hash command.
  • --header-files path β€” Specifies the location of header files to copy into the resulting JMOD file.
  • --help or -h β€” Prints a usage message.
  • --help-extra β€” Prints help for extra options.
  • --legal-notices path β€” Specifies the location of legal notices to copy into the resulting JMOD file.
  • --libs path β€” Specifies location of native libraries to copy into the resulting JMOD file.
  • --main-class class-name β€” Specifies main class to record in the module-info.class file.
  • --man-pages path β€” Specifies the location of man pages to copy into the resulting JMOD file.
  • --module-version module-version β€” Specifies the module version to record in the module-info.class file.
  • --module-path path or -p path β€” Specifies the module path. This option is required if you also specify --hash-modules.
  • --target-platform platform β€” Specifies the target platform of a JMOD file intended for a specific operating system and architecture. The value should follow the format <os>-<arch>, where <os> is the operating system and <arch> is the hardware architecture. Example values include linux-amd64, windows-amd64, and macos-aarch64.
  • --version β€” Prints version information of the jmod tool.
  • @filename β€” Reads options from the specified file.

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 prefixing a 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
  --target-platform "macos-aarch64" greetingsmod

🌈 EXTRA OPTIONS FOR JMOD 🌈

In addition to the options described in Options for jmod, the following are extra options that can be used with the command. these are the bonus tracks πŸ’Ώ

  • --do-not-resolve-by-default β€” Exclude from the default root set of modules.
  • --warn-if-resolved β€” Hint for a tool to issue a warning if the module is resolved. One of deprecated, deprecated-for-removal, or incubating.

πŸ‘‘ JMOD CREATE EXAMPLES πŸ‘‘

πŸŽ€ Create a JMOD file containing only compiled classes:

jmod create --class-path build/foo/classes jmods/foo1.jmod

πŸŽ€ Create a JMOD file specifying the date for the entries as 2022 March 15 00:00:00:

jmod create --class-path build/foo/classes --date 2022-03-15T00:00:00Z
   jmods/foo2.jmod

πŸŽ€ Create a JMOD file bundling compiled classes, native commands, configuration files, header files, native libraries, man pages, and metadata including the main class, module version, and target platform details:

jmod create --class-path mods/com.greetings --cmds commands
  --config configfiles --header-files src/h --libs lib
  --man-pages man --main-class com.greetings.Main --module-version 1.0
  --target-platform "macos-aarch64" greetingsmod

πŸ¦‹ JMOD HASH EXAMPLE πŸ¦‹

okay bestie, so this example is gonna show you exactly 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. it's giving "vibe check failed" energy and honestly? iconic behavior from the tool. 😭


  1. Create and compile the following .java files:
    • jmodhashex/src/ma/module-info.java
module ma {
  requires mb;
}
  • jmodhashex/src/mb/module-info.java
module mb {
}
  • jmodhashex2/src/ma/module-info.java
module ma {
  requires mb;
}
  • jmodhashex2/src/mb/module-info.java
module mb {
}
  1. Create a JMOD archive for each module. create the directories jmodhashex/jmods and jmodhashex2/jmods, and then run the following commands from the jmodhashex directory, then from the jmodhashex2 directory:
    • jmod create --class-path mods/ma jmods/ma.jmod
    • jmod create --class-path mods/mb jmods/mb.jmod
  2. Optionally preview the jmod hash command. run the following command from the jmodhashex directory:
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. ✨ it's a sneak peek, a little trailer, a dry run bestie, nothing gets written yet πŸ’…

  1. Record hash values in the JMOD archive files contained in the jmodhashex directory. run the following command from the jmodhashex directory:
jmod hash --module-path jmods --hash-modules .*

The command prints the following:

Hashes are recorded in module mb

slay, the hash is officially in its new home 🏑

  1. Print information about each JMOD archive contained in the jmodhashex directory. run the highlighted commands from the jmodhashex directory:
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

look at that hash sitting in mb like it owns the place πŸ‘‘

  1. Attempt to create a runtime image that contains the module ma from the directory jmodhashex2 but the module mb from the directory jmodhashex. run the following command from the jmodhashex2 directory:
    • Linux and macOS:
jlink --module-path $JAVA_HOME/jmods:jmods/ma.jmod:../jmod‐
hashex/jmods/mb.jmod --add-modules ma --output ma-app
  • Windows:
jlink --module-path %JA‐
VA_HOME%/jmods;jmods/ma.jmod;../jmod‐
hashex/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
and there it is β€” the moment the vibes do NOT match. πŸ’€ the hash of ma and the hash recorded in mb are literally different, so jlink says nope. no runtime image for you today, bestie. this is exactly what the hash check is for. πŸ™ˆ

and that's the whole example, start to finish β€” you built the archives, previewed the hash, recorded it, described it, and then watched the mismatch get caught in 4K. character development fr fr 🧚

sign-off time πŸŽ€ this little masterpiece comes from JDK 27-ea, dated 2026, and it lives in section JMOD(1) of your friendly neighborhood manual pages. go forth and hash responsibly, bestie πŸ«ΆπŸ’–

πŸ“¦ where this page comes from
  • epel 10: java-latest-openjdk-devel 1:27.0.0.0.35-0.0.1.0.ea.el10_3 Β· Apache-1.1 AND Apache-2.0 AND LicenseRef-Callaway-BSD AND LicenseRef-Callaway-BSD-with-advertising AND GPL-1.0-or-later AND GPL-2.0-only AND LicenseRef-Callaway-GPLv2-with-exceptions AND IJG AND LicenseRef-Callaway-LGPLv2+ AND LicenseRef-Callaway-MIT AND MPL-2.0 AND LicenseRef-Callaway-Public-Domain AND W3C AND Zlib AND ISC AND FTL AND LicenseRef-RSA
  • epel 10: java-latest-openjdk-devel-fastdebug 1:27.0.0.0.35-0.0.1.0.ea.el10_3 Β· Apache-1.1 AND Apache-2.0 AND LicenseRef-Callaway-BSD AND LicenseRef-Callaway-BSD-with-advertising AND GPL-1.0-or-later AND GPL-2.0-only AND LicenseRef-Callaway-GPLv2-with-exceptions AND IJG AND LicenseRef-Callaway-LGPLv2+ AND LicenseRef-Callaway-MIT AND MPL-2.0 AND LicenseRef-Callaway-Public-Domain AND W3C AND Zlib AND ISC AND FTL AND LicenseRef-RSA
  • epel 10: java-latest-openjdk-devel-slowdebug 1:27.0.0.0.35-0.0.1.0.ea.el10_3 Β· Apache-1.1 AND Apache-2.0 AND LicenseRef-Callaway-BSD AND LicenseRef-Callaway-BSD-with-advertising AND GPL-1.0-or-later AND GPL-2.0-only AND LicenseRef-Callaway-GPLv2-with-exceptions AND IJG AND LicenseRef-Callaway-LGPLv2+ AND LicenseRef-Callaway-MIT AND MPL-2.0 AND LicenseRef-Callaway-Public-Domain AND W3C AND Zlib AND ISC AND FTL AND LicenseRef-RSA
  • epel 9: java-latest-openjdk-devel 1:27.0.0.0.35-0.0.1.0.ea.el9 Β· Apache-1.1 AND Apache-2.0 AND LicenseRef-Callaway-BSD AND LicenseRef-Callaway-BSD-with-advertising AND GPL-1.0-or-later AND GPL-2.0-only AND LicenseRef-Callaway-GPLv2-with-exceptions AND IJG AND LicenseRef-Callaway-LGPLv2+ AND LicenseRef-Callaway-MIT AND MPL-2.0 AND LicenseRef-Callaway-Public-Domain AND W3C AND Zlib AND ISC AND FTL AND LicenseRef-RSA
  • epel 9: java-latest-openjdk-devel-fastdebug 1:27.0.0.0.35-0.0.1.0.ea.el9 Β· Apache-1.1 AND Apache-2.0 AND LicenseRef-Callaway-BSD AND LicenseRef-Callaway-BSD-with-advertising AND GPL-1.0-or-later AND GPL-2.0-only AND LicenseRef-Callaway-GPLv2-with-exceptions AND IJG AND LicenseRef-Callaway-LGPLv2+ AND LicenseRef-Callaway-MIT AND MPL-2.0 AND LicenseRef-Callaway-Public-Domain AND W3C AND Zlib AND ISC AND FTL AND LicenseRef-RSA
  • epel 9: java-latest-openjdk-devel-slowdebug 1:27.0.0.0.35-0.0.1.0.ea.el9 Β· Apache-1.1 AND Apache-2.0 AND LicenseRef-Callaway-BSD AND LicenseRef-Callaway-BSD-with-advertising AND GPL-1.0-or-later AND GPL-2.0-only AND LicenseRef-Callaway-GPLv2-with-exceptions AND IJG AND LicenseRef-Callaway-LGPLv2+ AND LicenseRef-Callaway-MIT AND MPL-2.0 AND LicenseRef-Callaway-Public-Domain AND W3C AND Zlib AND ISC AND FTL AND LicenseRef-RSA
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms