1
.\" Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
2
.\" DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
.\" This code is free software; you can redistribute it and/or modify it
5
.\" under the terms of the GNU General Public License version 2 only, as
6
.\" published by the Free Software Foundation.
8
.\" This code is distributed in the hope that it will be useful, but WITHOUT
9
.\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
.\" FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11
.\" version 2 for more details (a copy is included in the LICENSE file that
12
.\" accompanied this code).
14
.\" You should have received a copy of the GNU General Public License version
15
.\" 2 along with this work; if not, write to the Free Software Foundation,
16
.\" Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
.\" Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19
.\" or visit www.oracle.com if you need additional information or have any
22
.\" Automatically generated by Pandoc 2.19.2
24
.\" Define V font for inline verbatim, using C font in formats
25
.\" that render this, and otherwise B font.
26
.ie "\f[CB]x\f[R]"x" \{\
38
.TH "JMOD" "1" "2025" "JDK 24-ea" "JDK Commands"
42
jmod - create JMOD files and list the content of existing JMOD files
46
(\f[V]create\f[R]|\f[V]extract\f[R]|\f[V]list\f[R]|\f[V]describe\f[R]|\f[V]hash\f[R])
47
[\f[I]options\f[R]] \f[I]jmod-file\f[R]
49
Includes the following:
51
\f[B]Main operation modes\f[R]
54
Creates a new JMOD archive file.
57
Extracts all the files from the JMOD archive file.
60
Prints the names of all the entries.
63
Prints the module details.
66
Determines leaf modules and records the hashes of the dependencies that
67
directly and indirectly require them.
72
See \f[B]Options for jmod\f[R].
77
Specifies the name of the JMOD file to create or from which to retrieve
81
\f[B]Note:\f[R] For most development tasks, including deploying modules
82
on the module path or publishing them to a Maven repository, continue to
83
package modules in modular JAR files.
84
The \f[V]jmod\f[R] tool is intended for modules that have native
85
libraries or other configuration files or for modules that you intend to
86
link, with the \f[B]jlink\f[R] tool, to a runtime image.
88
The JMOD file format lets you aggregate files other than
89
\f[V].class\f[R] files, metadata, and resources.
90
This format is transportable but not executable, which means that you
91
can use it during compile time or link time but not at run time.
93
Many \f[V]jmod\f[R] options involve specifying a path whose contents are
94
copied into the resulting JMOD files.
95
These options copy all the contents of the specified path, including
96
subdirectories and their contents, but exclude files whose names match
97
the pattern specified by the \f[V]--exclude\f[R] option.
99
With the \f[V]--hash-modules\f[R] option or the \f[V]jmod hash\f[R]
100
command, you can, in each module\[aq]s descriptor, record hashes of the
101
content of the modules that are allowed to depend upon it, thus
102
\[dq]tying\[dq] together these modules.
103
This enables a package to be exported to one or more specifically-named
104
modules and to no others through qualified exports.
105
The runtime verifies if the recorded hash of a module matches the one
106
resolved at run time; if not, the runtime returns an error.
109
\f[V]--class-path\f[R] \f[I]path\f[R]
110
Specifies the location of application JAR files or a directory
111
containing classes to copy into the resulting JMOD file.
113
\f[V]--cmds\f[R] \f[I]path\f[R]
114
Specifies the location of native commands to copy into the resulting
117
\f[V]--compress\f[R] \f[I]compress\f[R]
118
Specifies the compression to use in creating the JMOD file.
119
The accepted values are \f[V]zip-[0-9]\f[R], where \f[V]zip-0\f[R]
120
provides no compression, and \f[V]zip-9\f[R] provides the best
122
Default is \f[V]zip-6\f[R].
124
\f[V]--config\f[R] \f[I]path\f[R]
125
Specifies the location of user-editable configuration files to copy into
126
the resulting JMOD file.
128
\f[V]--date\f[R]\f[I]TIMESTAMP\f[R]
129
The timestamp in ISO-8601 extended offset date-time with optional
130
time-zone format, to use for the timestamp of the entries, e.g.
131
\[dq]2022-02-12T12:30:00-05:00\[dq].
133
\f[V]--dir\f[R] \f[I]path\f[R]
134
Specifies the location where \f[V]jmod\f[R] puts extracted files from
135
the specified JMOD archive.
138
Performs a dry run of hash mode.
139
It identifies leaf modules and their required modules without recording
142
\f[V]--exclude\f[R] \f[I]pattern-list\f[R]
143
Excludes files matching the supplied comma-separated pattern list, each
144
element using one the following forms:
147
\f[I]glob-pattern\f[R]
149
\f[V]glob:\f[R]\f[I]glob-pattern\f[R]
151
\f[V]regex:\f[R]\f[I]regex-pattern\f[R]
153
See the \f[B]\f[VB]FileSystem.getPathMatcher\f[B]\f[R] method for the
154
syntax of \f[I]glob-pattern\f[R].
155
See the \f[B]\f[VB]Pattern\f[B]\f[R] class for the syntax of
156
\f[I]regex-pattern\f[R], which represents a regular expression.
159
\f[V]--hash-modules\f[R] \f[I]regex-pattern\f[R]
160
Determines the leaf modules and records the hashes of the dependencies
161
directly and indirectly requiring them, based on the module graph of the
162
modules matching the given \f[I]regex-pattern\f[R].
163
The hashes are recorded in the JMOD archive file being created, or a
164
JMOD archive or modular JAR on the module path specified by the
165
\f[V]jmod hash\f[R] command.
167
\f[V]--header-files\f[R] \f[I]path\f[R]
168
Specifies the location of header files to copy into the resulting JMOD
171
\f[V]--help\f[R] or \f[V]-h\f[R]
172
Prints a usage message.
174
\f[V]--help-extra\f[R]
175
Prints help for extra options.
177
\f[V]--legal-notices\f[R] \f[I]path\f[R]
178
Specifies the location of legal notices to copy into the resulting JMOD
181
\f[V]--libs\f[R] \f[I]path\f[R]
182
Specifies location of native libraries to copy into the resulting JMOD
185
\f[V]--main-class\f[R] \f[I]class-name\f[R]
186
Specifies main class to record in the module-info.class file.
188
\f[V]--man-pages\f[R] \f[I]path\f[R]
189
Specifies the location of man pages to copy into the resulting JMOD
192
\f[V]--module-version\f[R] \f[I]module-version\f[R]
193
Specifies the module version to record in the module-info.class file.
195
\f[V]--module-path\f[R] \f[I]path\f[R] or \f[V]-p\f[R] \f[I]path\f[R]
196
Specifies the module path.
197
This option is required if you also specify \f[V]--hash-modules\f[R].
199
\f[V]--target-platform\f[R] \f[I]platform\f[R]
200
Specifies the target platform.
203
Prints version information of the \f[V]jmod\f[R] tool.
205
\f[V]\[at]\f[R]\f[I]filename\f[R]
206
Reads options from the specified file.
209
An options file is a text file that contains the options and values that
210
you would ordinarily enter in a command prompt.
211
Options may appear on one line or on several lines.
212
You may not specify environment variables for path names.
213
You may comment out lines by prefixinga hash symbol (\f[V]#\f[R]) to the
214
beginning of the line.
216
The following is an example of an options file for the \f[V]jmod\f[R]
221
#Wed Dec 07 00:40:19 EST 2016
222
create --class-path mods/com.greetings --module-path mlib
223
--cmds commands --config configfiles --header-files src/h
224
--libs lib --main-class com.greetings.Main
225
--man-pages man --module-version 1.0
226
--os-arch \[dq]x86_x64\[dq] --os-name \[dq]macOS\[dq]
227
--os-version \[dq]10.10.5\[dq] greetingsmod
231
.SH EXTRA OPTIONS FOR JMOD
233
In addition to the options described in \f[B]Options for jmod\f[R], the
234
following are extra options that can be used with the command.
236
\f[V]--do-not-resolve-by-default\f[R]
237
Exclude from the default root set of modules
239
\f[V]--warn-if-resolved\f[R]
240
Hint for a tool to issue a warning if the module is resolved.
241
One of deprecated, deprecated-for-removal, or incubating.
242
.SH JMOD CREATE EXAMPLE
244
The following is an example of creating a JMOD file:
248
jmod create --class-path mods/com.greetings --cmds commands
249
--config configfiles --header-files src/h --libs lib
250
--main-class com.greetings.Main --man-pages man --module-version 1.0
251
--os-arch \[dq]x86_x64\[dq] --os-name \[dq]macOS\[dq]
252
--os-version \[dq]10.10.5\[dq] greetingsmod
256
Create a JMOD file specifying the date for the entries as
257
\f[V]2022 March 15 00:00:00\f[R]:
261
jmod create --class-path build/foo/classes --date 2022-03-15T00:00:00Z
267
The following example demonstrates what happens when you try to link a
268
leaf module (in this example, \f[V]ma\f[R]) with a required module
269
(\f[V]mb\f[R]), and the hash value recorded in the required module
270
doesn\[aq]t match that of the leaf module.
272
Create and compile the following \f[V].java\f[R] files:
275
\f[V]jmodhashex/src/ma/module-info.java\f[R]
287
\f[V]jmodhashex/src/mb/module-info.java\f[R]
298
\f[V]jmodhashex2/src/ma/module-info.java\f[R]
310
\f[V]jmodhashex2/src/mb/module-info.java\f[R]
322
Create a JMOD archive for each module.
323
Create the directories \f[V]jmodhashex/jmods\f[R] and
324
\f[V]jmodhashex2/jmods\f[R], and then run the following commands from
325
the \f[V]jmodhashex\f[R] directory, then from the \f[V]jmodhashex2\f[R]
329
\f[V]jmod create --class-path mods/ma jmods/ma.jmod\f[R]
331
\f[V]jmod create --class-path mods/mb jmods/mb.jmod\f[R]
334
Optionally preview the \f[V]jmod hash\f[R] command.
335
Run the following command from the \f[V]jmodhashex\f[R] directory:
338
\f[V]jmod hash --dry-run -module-path jmods --hash-modules .*\f[R]
340
The command prints the following:
346
hashes ma SHA-256 07667d5032004b37b42ec2bb81b46df380cf29e66962a16481ace2e71e74073a
350
This indicates that the \f[V]jmod hash\f[R] command (without the
351
\f[V]--dry-run\f[R] option) will record the hash value of the leaf
352
module \f[V]ma\f[R] in the module \f[V]mb\f[R].
355
Record hash values in the JMOD archive files contained in the
356
\f[V]jmodhashex\f[R] directory.
357
Run the following command from the \f[V]jmodhashex\f[R] directory:
361
\f[V]jmod hash --module-path jmods --hash-modules .*\f[R]
364
The command prints the following:
367
\f[V]Hashes are recorded in module mb\f[R]
371
Print information about each JMOD archive contained in the
372
\f[V]jmodhashex\f[R] directory.
373
Run the highlighted commands from the \f[V]jmodhashex\f[R] directory:
378
jmod describe jmods/ma.jmod
381
requires mandated java.base
384
jmod describe jmods/mb.jmod
387
requires mandated java.base
388
hashes ma SHA-256 07667d5032004b37b42ec2bb81b46df380cf29e66962a16481ace2e71e74073a
393
Attempt to create a runtime image that contains the module \f[V]ma\f[R]
394
from the directory \f[V]jmodhashex2\f[R] but the module \f[V]mb\f[R]
395
from the directory \f[V]jmodhashex\f[R].
396
Run the following command from the \f[V]jmodhashex2\f[R] directory:
399
\f[B]Linux and macOS:\f[R]
403
\f[V]jlink --module-path $JAVA_HOME/jmods:jmods/ma.jmod:../jmodhashex/jmods/mb.jmod --add-modules ma --output ma-app\f[R]
411
\f[V]jlink --module-path %JAVA_HOME%/jmods;jmods/ma.jmod;../jmodhashex/jmods/mb.jmod --add-modules ma --output ma-app\f[R]
415
The command prints an error message similar to the following:
419
Error: Hash of ma (a2d77889b0cb067df02a3abc39b01ac1151966157a68dc4241562c60499150d2) differs to
420
expected hash (07667d5032004b37b42ec2bb81b46df380cf29e66962a16481ace2e71e74073a) recorded in mb