JMOD(1)
π JMOD(1) β from the JDK Commands manual π
okay bestie, gather round: this is the glow-up of jmod, the tool that makes JMOD files and peeks inside the ones you already have. no cap, it's giving βbuild-time iconβ energy. β¨
πΈ NAME πΈ
jmod β create JMOD files and list the content of existing JMOD files. periodt. π
β¨ SYNOPSIS β¨
jmod (create|extract|list|describe|hash) [options] jmod-file
Includes the following:
- Main operation modes
createβ Creates a new JMOD archive file. πextractβ Extracts all the files from the JMOD archive file.listβ Prints the names of all the entries.describeβ Prints the module details.hashβ Determines leaf modules and records the hashes of the dependencies that directly and indirectly require them.
- Options
optionsβ See Options for jmod below, bestie. π
- 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. Thejmodtool is intended for modules that have native libraries or other configuration files or for modules that you intend to link, with thejlinktool, 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 like, it's backstage, not onstage. π
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. copy everything, then let --exclude do its little vibe check. π¦
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. that's the βtrust but verifyβ of module land, fr fr. π₯
π OPTIONS FOR JMOD π
--class-pathpath β Specifies the location of application JAR files or a directory containing classes to copy into the resulting JMOD file.--cmdspath β Specifies the location of native commands to copy into the resulting JMOD file.--compresscompress β Specifies the compression to use in creating the JMOD file. The accepted values arezip-[0-9], wherezip-0provides no compression, andzip-9provides the best compression. Default iszip-6.--configpath β 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".--dirpath β Specifies the location wherejmodputs 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.--excludepattern-list β Excludes files matching the supplied comma-separated pattern list, each element using one the following forms:glob-patternglob:glob-patternregex: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-modulesregex-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 givenregex-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 thejmod hashcommand.--header-filespath β Specifies the location of header files to copy into the resulting JMOD file.--helpor-hβ Prints a usage message.--help-extraβ Prints help for extra options.--legal-noticespath β Specifies the location of legal notices to copy into the resulting JMOD file.--libspath β Specifies location of native libraries to copy into the resulting JMOD file.--main-classclass-name β Specifies main class to record in themodule-info.classfile.--man-pagespath β Specifies the location of man pages to copy into the resulting JMOD file.--module-versionmodule-version β Specifies the module version to record in themodule-info.classfile.--module-pathpath or-ppath β Specifies the module path. This option is required if you also specify--hash-modules.--target-platformplatform β Specifies the target platform.--versionβ Prints version information of thejmodtool.@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.
Here's an example 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 "macOS"
--os-version "10.10.5" 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.
--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 ofdeprecated,deprecated-for-removal, orincubating.
π JMOD CREATE EXAMPLE π
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 "macOS"
--os-version "10.10.5" greetingsmod
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/foo1.jmod
π₯ JMOD HASH EXAMPLE π₯
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. this is the drama arc of the page, bestie. π
- Create and compile the following
.javafiles: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 {
}
- Create a JMOD archive for each module. Create the directories
jmodhashex/jmodsandjmodhashex2/jmods, and then run the following commands from thejmodhashexdirectory, then from thejmodhashex2directory:jmod create --class-path mods/ma jmods/ma.jmodjmod create --class-path mods/mb jmods/mb.jmod
- Optionally preview the
jmod hashcommand. Run the following command from thejmodhashexdirectory:
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.
- Record hash values in the JMOD archive files contained in the
jmodhashexdirectory. Run the following command from thejmodhashexdirectory:
jmod hash --module-path jmods --hash-modules .*
The command prints the following:
Hashes are recorded in module mb
- Print information about each JMOD archive contained in the
jmodhashexdirectory. Run the highlighted commands from thejmodhashexdirectory:
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
- Attempt to create a runtime image that contains the module
mafrom the directoryjmodhashex2but the modulembfrom the directoryjmodhashex. Run the following command from thejmodhashex2directory:- Linux and macOS:
jlink --module-path $JAVA_HOME/jmods:jmods/ma.jmod:../jmodhashex/jmods/mb.jmod --add-modules ma --output ma-app
- Windows:
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
πΊ okay bye bestie β this lil masterpiece is from JDK 22, dated 2024, and it's the JMOD(1) manual page. slay. π«Ά
π¦ where this page comes from
- opensuse-leap 16.0: java-22-openjdk-devel 22.0.2.0-160000.1.1 Β· Apache-1.1 AND Apache-2.0 AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-only WITH Classpath-exception-2.0 AND LGPL-2.0-only AND MPL-1.0 AND MPL-1.1 AND SUSE-Public-Domain AND W3C
- opensuse-leap 16.0: java-22-openjdk-devel 22.0.2.0-160000.1.1 Β· Apache-1.1 AND Apache-2.0 AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-only WITH Classpath-exception-2.0 AND LGPL-2.0-only AND MPL-1.0 AND MPL-1.1 AND SUSE-Public-Domain AND W3C
- opensuse-leap 16.0: java-22-openjdk-devel 22.0.2.0-160000.1.1 Β· Apache-1.1 AND Apache-2.0 AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-only WITH Classpath-exception-2.0 AND LGPL-2.0-only AND MPL-1.0 AND MPL-1.1 AND SUSE-Public-Domain AND W3C
- opensuse-leap 16.0: java-22-openjdk-devel 22.0.2.0-160000.1.1 Β· Apache-1.1 AND Apache-2.0 AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-only WITH Classpath-exception-2.0 AND LGPL-2.0-only AND MPL-1.0 AND MPL-1.1 AND SUSE-Public-Domain AND W3C
- Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms