Java Module Commands: describe-module, jdeps, jmod and jlink (OCP 21)
The module tools for the OCP 21 exam: built-in java and jdk modules, java --describe-module, --list-modules and --show-module-resolution, jar --describe-module, jdeps with -summary and --jdk-internals, jmod modes, jlink runtime images and jpackage installers, with every option form.
kvi5hnuCode Sprout team member11 min readOn this page
You've built and run modules with javac, jar and java. The JDK has more tools for inspecting modules and for shipping them: describing a module's declaration, listing modules, finding the dependencies of old JARs, and building a trimmed-down Java runtime or a native installer. The exam doesn't expect you to read their output closely, but it does expect you to know which tool does what and the exact option spellings. Every command and output below was run on JDK 21 and JDK 25.
The JDK's own modules
Since Java 9 the JDK itself is split into modules. A JDK 21 or 25 build has about 70 of them, and their names start with one of two prefixes:
java.modules are part of the Java SE standard, so every Java implementation has them.jdk.modules are specific to the JDK implementation: tools, extra features and internal support code.
Know these by name:
| Module | Contains |
|---|---|
java.base | java.lang, java.util, java.io, java.nio, java.time, java.util.concurrent, java.text, java.math... nearly everything on the exam |
java.sql | JDBC (java.sql, javax.sql) |
java.logging | java.util.logging |
java.xml | XML parsing and processing |
java.desktop | AWT and Swing user interfaces |
java.base is special: every module reads it automatically, which descriptors show as requires java.base mandated. Writing requires java.base; yourself compiles, but it's redundant.
The full list of java. modules is the same in Java 21 and 25:
java.base, java.compiler, java.datatransfer, java.desktop, java.instrument,
java.logging, java.management, java.management.rmi, java.naming, java.net.http,
java.prefs, java.rmi, java.scripting, java.se, java.security.jgss,
java.security.sasl, java.smartcardio, java.sql, java.sql.rowset,
java.transaction.xa, java.xml, java.xml.crypto
jdk. examples include jdk.compiler (javac), jdk.jshell, jdk.jlink, jdk.httpserver, jdk.jfr, jdk.zipfs, jdk.localedata, jdk.charsets and jdk.unsupported. You don't need to memorize these. You only need to recognize that a module name like jdk.something is plausible and that java. modules are the standard APIs.
java: describing, listing and showing resolution
--describe-module / -d
java -p mods -d garden.plants
java --module-path mods --describe-module garden.plants
garden.plants file:///.../mods/garden.plants.jar
exports garden.plants.care
requires java.base mandated
requires garden.water
contains garden.plants.notes
The first line is the module name and its location. The other lines restate the module declaration in a fixed vocabulary:
| Output line | Comes from |
|---|---|
exports p | exports p; |
qualified exports p to m | exports p to m; |
requires m | requires m; |
requires m transitive | requires transitive m; (the modifier comes after the name) |
requires java.base mandated | added to every module |
opens p / qualified opens p to m | opens directives |
uses T / provides T with C | service directives |
contains p | a package that's neither exported nor opened |
JDK modules can be described without -p. For example, java -d java.sql shows requires java.logging transitive, exports javax.sql and uses java.sql.Driver.
--list-modules
java --list-modules # just the JDK's modules, with versions: java.base@21.0.x ...
java -p mods --list-modules # also every module found in mods, with its location
It lists the observable modules and then exits without running anything, even if you also pass -m.
--show-module-resolution
java --show-module-resolution -p mods -m garden.plants/garden.plants.care.Schedule
This prints how the module graph is built and then runs the program. The output starts with the root module, then lines like garden.plants requires garden.water ... and java.base binds jdk.localedata ... (binds lines come from service binding). The program's own output follows at the end. It's a debugging aid. You only need to know what it does.
java option | Purpose |
|---|---|
-p / --module-path | where modules are found |
-m / --module | module (and main class) to run |
-d / --describe-module | print a module's declaration details |
--list-modules | list observable modules, don't run |
--show-module-resolution | print resolution details, then run |
jar --describe-module
jar -f mods/garden.plants.jar -d
jar --file mods/garden.plants.jar --describe-module
The output matches java -d, except that the location points inside the JAR (...garden.plants.jar!/module-info.class). For a JAR without module-info.class, jar -d reports No module descriptor found. Derived automatic module. and shows the name Java would give it as an automatic module (article 77).
jar option | Purpose |
|---|---|
-c / --create | create a JAR |
-v / --verbose | list what's being done |
-f / --file | the JAR file name |
-C <dir> | change to a folder before adding files |
-d / --describe-module | describe the module in the JAR |
jdeps: what does this code actually use?
--describe-module only repeats what the declaration says. jdeps reads the compiled classes and reports which packages and modules they really use. Its main job on the exam is preparing an old, non-modular JAR for migration. For example, the code below is in kiosk.jar, a plain JAR with no module-info:
package kiosk.core;
import java.sql.Timestamp;
import java.util.logging.Logger;
public class Ticketer {
public String stamp() {
Logger.getGlobal().info("stamp");
return new Timestamp(0L).toString();
}
public int pageSize() { return sun.misc.Unsafe.getUnsafe().pageSize(); }
}
jdeps kiosk.jar
kiosk.jar -> java.base
kiosk.jar -> java.logging
kiosk.jar -> java.sql
kiosk.jar -> jdk.unsupported
kiosk.core -> java.lang java.base
kiosk.core -> java.sql java.sql
kiosk.core -> java.util.logging java.logging
kiosk.core -> sun.misc JDK internal API (jdk.unsupported)
...
The first block lists the modules this JAR would need to require once it became a module. The second block shows each package used and the module it belongs to.
jdeps option | Purpose |
|---|---|
-s / -summary | only the module-level summary (the first block) |
--jdk-internals / -jdkinternals | list uses of JDK internal APIs and suggest replacements |
--module-path <path> | where to find other modules. There's no short form. |
jdeps -s kiosk.jar
jdeps --jdk-internals kiosk.jar
jdeps -summary --module-path mods mods/garden.plants.jar
--jdk-internals produces a table such as sun.misc.Unsafe See https://openjdk.org/jeps/260, pointing to the documented replacement.
The single-dash long names (-summary, -jdkinternals) are older spellings that still work. Two more options are handy in real migrations, though not on the exam: --print-module-deps prints a comma-separated module list for jlink, and --generate-module-info <dir> drafts a module-info.java for a JAR.
About jdk.unsupported and sun.misc.Unsafe
jdk.unsupported holds a few internal classes, most famously sun.misc.Unsafe, that so many libraries depended on that they were kept reachable when the JDK became modular. javac warns ("internal proprietary API and may be removed"). Since then, the JDK has been closing that door: Java 23 deprecated Unsafe's memory-access methods for removal, and Java 24 prints a run-time warning when they're used. The supported replacements are VarHandle and the Foreign Function & Memory API.
jmod: JMOD files
A JMOD file is an alternative package format, for modules that need native libraries or other files a JAR can't hold. Oracle recommends plain JARs for everything else. JMOD files are used at compile time and link time (by jlink). They can't be put on the module path at run time: java fails with "JMOD format not supported at execution time".
jmod works in modes. You don't need its options, only the mode names:
| Mode | What it does |
|---|---|
create | create a JMOD file |
extract | extract all its files, like unzipping |
list | list the files inside |
describe | print the module details, such as requires |
hash | record hashes of tied modules |
jmod create --class-path water water.jmod
jmod describe water.jmod
jlink: a custom runtime image
A full JDK takes hundreds of megabytes: the JDK 25 used for this article is 294 MB on disk. A modular application usually needs a few modules of it. jlink builds a runtime image that contains only your modules and the JDK modules they need:
jlink --module-path mods --add-modules garden.plants --output gardenApp
jlink -p mods --add-modules garden.plants --output gardenApp
-p/--module-path: where your modules are. The JDK's own modules are found automatically.--add-modules: the root modules. Everything they require is added too.--output: the folder to create. It must not exist yet ("directory already exists").
The result is a folder, not a single file. It holds bin (with its own java launcher), conf, include, legal, lib, usually man, and a release file. gardenApp/bin/java --list-modules shows exactly garden.plants, garden.water and java.base, and gardenApp/bin/java -m garden.plants/garden.plants.care.Schedule runs the program with no JDK installed. This image came to about 49 MB. Adding --strip-debug --no-header-files --no-man-pages --compress=zip-9 brought it down to 32 MB. jlink works only with modular code. Every module in the image needs a descriptor, and a plain JAR on the module path is rejected with "automatic module cannot be used with jlink".

jpackage: a native installer
jlink gives you a folder. jpackage (Java 16+) goes one step further and produces a platform-specific application package: .dmg or .pkg on macOS, .exe or .msi on Windows, .deb or .rpm on Linux. Unlike jlink, it accepts modular and non-modular applications:
# modular
jpackage --name plantsTask --module-path mods --module garden.plants/garden.plants.care.Schedule
jpackage -n plantsTask -p mods -m garden.plants/garden.plants.care.Schedule
# non-modular: a folder holding the JAR, which JAR to start, and which class
jpackage --name helloApp --input lib --main-jar hello.jar --main-class app.Hello
jpackage -n helloApp -i lib --main-jar hello.jar --main-class app.Hello
jpackage option | Purpose |
|---|---|
-n / --name | application name, used in the output file name |
--app-version | version in the file name. The default is 1.0, so you get, for example, plantsTask-1.0.dmg |
-p / --module-path, -m / --module | as for java |
--add-modules | extra modules to include, as for jlink |
-i / --input | folder with the non-modular JARs |
--main-jar, --main-class | the JAR and class to start, for non-modular apps |
-t / --type | the package type, for example app-image, dmg or msi. Each platform has a default. |
Building an installer needs the platform's own packaging tools. --type app-image skips the installer and just creates the runnable application folder.
All the commands in one place
| Task | Commands |
|---|---|
| Compile non-modular code | javac -cp <path> -d <dir> <files> (also -classpath, --class-path) |
| Run non-modular code | java -cp <path> pkg.Class (also -classpath, --class-path) |
| Compile a module | javac -p <path> -d <dir> <files incl. module-info.java> (also --module-path) |
| Run a module | java -p <path> -m mod/pkg.Class (also --module-path, --module) |
| Describe a module | java -p <path> -d mod / java --module-path <path> --describe-module mod / jar -f x.jar -d / jar --file x.jar --describe-module |
| List modules | java --list-modules / java -p <path> --list-modules |
| Show resolution | java --show-module-resolution -p <path> -m mod/pkg.Class |
| Dependencies | jdeps -s x.jar / jdeps -summary --module-path <path> x.jar / jdeps --jdk-internals x.jar / jdeps -jdkinternals x.jar |
| Runtime image | jlink -p <path> --add-modules mod --output <dir> (also --module-path) |
| Installer | jpackage -n name -p <path> -m mod/pkg.Class / jpackage -n name -i <dir> --main-jar x.jar --main-class pkg.Class |
What's current
- All these tools and options work the same in Java 21 and Java 25.
jpackagebecame a standard tool in Java 16. - Since Java 24, a JDK may be built without the
jmodsfolder, andjlinkcan then link from the running JDK's own image instead (JEP 493). The Temurin 25 build used here has nojmodsfolder, yetjlinkworked. The Corretto 21 build still shipsjmods. - For
jlink --compress, the old numeric levels (0,1,2) are deprecated since Java 21 in favor ofzip-0tozip-9. - The
javalauncher also has escape hatches such as--add-modules,--add-exports,--add-opensand--add-reads, which change module rules from the command line. They're useful during migration, but they make a setup hard to understand. Fix the module declarations instead whenever you can.
Exam traps from this article
A complete example
This program builds two modules and a non-modular JAR that uses java.sql, java.logging and sun.misc.Unsafe. Then it runs the real JDK tools in-process through ToolProvider: jar --describe-module, jdeps with -s, --jdk-internals and --module-path, jmod create, describe and list, and jlink. Finally it starts the program from the new runtime image's own bin/java as a separate process. Temporary paths are shown as <tmp>.
import java.io.*;
import java.nio.file.*;
import java.util.*;
import java.util.spi.ToolProvider;
public class Solution {
static Path root;
static void write(String file, String code) throws IOException {
Path p = root.resolve(file);
Files.createDirectories(p.getParent());
Files.writeString(p, code);
}
// Runs a JDK tool in-process and prints its output with the temp folder hidden.
// 'keep' limits the output to lines containing one of the given words.
static void tool(String name, List<String> keep, String... args) {
System.out.println("$ " + name + " " + String.join(" ", args));
String[] full = Arrays.stream(args)
.map(a -> a.contains("/") || a.endsWith(".jar") || a.endsWith(".jmod")
? root.resolve(a).toString() : a)
.toArray(String[]::new);
var out = new StringWriter();
ToolProvider.findFirst(name).orElseThrow()
.run(new PrintWriter(out), new PrintWriter(Writer.nullWriter()), full);
show(out.toString(), keep);
}
static void show(String text, List<String> keep) {
text.lines()
.map(l -> l.replace(root.toUri().toString(), "file:///<tmp>/")
.replace(root.toString(), "<tmp>").stripTrailing())
.filter(l -> !l.isBlank())
.filter(l -> keep.isEmpty() || keep.stream().anyMatch(l::contains))
.forEach(l -> System.out.println(" " + l.replaceAll(" {3,}", " ")));
}
// Runs a program from the generated runtime image as a separate process.
static void runImage(List<String> keep, String... args) throws Exception {
String exe = System.getProperty("os.name").startsWith("Windows") ? "java.exe" : "java";
List<String> cmd = new ArrayList<>(List.of(root.resolve("gardenApp/bin/" + exe).toString()));
cmd.addAll(List.of(args));
System.out.println("$ gardenApp/bin/java " + String.join(" ", args));
Process p = new ProcessBuilder(cmd).redirectErrorStream(true).start();
String text = new String(p.getInputStream().readAllBytes());
p.waitFor();
show(text.replaceAll("@[0-9.]+", ""), keep); // hide the JDK version number
}
static void deleteTree(Path dir) throws IOException {
try (var paths = Files.walk(dir)) {
for (Path p : paths.sorted(Comparator.reverseOrder()).toList()) {
Files.delete(p);
}
}
}
public static void main(String[] args) throws Exception {
root = Files.createTempDirectory("tools");
try {
// Two modules, as in the earlier articles
write("water/garden/water/Sprinkler.java", """
package garden.water;
public class Sprinkler {
public static void main(String... a) { System.out.println("Beds watered"); }
}
""");
write("water/module-info.java", "module garden.water { exports garden.water; }\n");
write("plants/garden/plants/care/Schedule.java", """
package garden.plants.care;
public class Schedule {
public static void main(String[] a) {
garden.water.Sprinkler.main();
System.out.println("Schedule ready");
}
}
""");
write("plants/garden/plants/notes/Log.java", "package garden.plants.notes;\npublic class Log { }\n");
write("plants/module-info.java", """
module garden.plants {
exports garden.plants.care;
requires garden.water;
}
""");
// A plain, non-modular JAR that uses JDK modules and an internal API
write("legacy/kiosk/core/Ticketer.java", """
package kiosk.core;
import java.sql.Timestamp;
import java.util.logging.Logger;
public class Ticketer {
public String stamp() {
Logger.getGlobal().info("stamp");
return new Timestamp(0L).toString();
}
public int pageSize() { return sun.misc.Unsafe.getUnsafe().pageSize(); }
}
""");
Files.createDirectories(root.resolve("mods"));
List<String> none = List.of();
System.out.println("== Build (output hidden)");
for (String[] step : new String[][]{
{"javac", "--release", "21", "-p", "mods/", "-d", "water/", "water/garden/water/Sprinkler.java", "water/module-info.java"},
{"jar", "-cf", "mods/garden.water.jar", "-C", "water/", "."},
{"javac", "--release", "21", "-p", "mods/", "-d", "plants/",
"plants/garden/plants/care/Schedule.java", "plants/garden/plants/notes/Log.java", "plants/module-info.java"},
{"jar", "-cf", "mods/garden.plants.jar", "-C", "plants/", "."},
{"javac", "--release", "21", "-d", "legacy/", "legacy/kiosk/core/Ticketer.java"},
{"jar", "-cf", "kiosk.jar", "-C", "legacy/", "."}}) {
String[] full = Arrays.stream(step).skip(1)
.map(a -> a.contains("/") || a.endsWith(".jar") ? root.resolve(a).toString() : a)
.toArray(String[]::new);
int code = ToolProvider.findFirst(step[0]).orElseThrow()
.run(new PrintWriter(Writer.nullWriter()), new PrintWriter(Writer.nullWriter()), full);
System.out.println(" " + step[0] + " ... " + (code == 0 ? "ok" : "exit " + code));
}
System.out.println("\n== Describe modules with jar");
tool("jar", none, "-f", "mods/garden.plants.jar", "-d");
tool("jar", none, "--file", "kiosk.jar", "--describe-module");
System.out.println("\n== Dependencies with jdeps");
tool("jdeps", none, "-s", "kiosk.jar");
tool("jdeps", List.of("->", "Unsafe"), "--jdk-internals", "kiosk.jar");
tool("jdeps", none, "-summary", "--module-path", "mods/", "mods/garden.plants.jar");
System.out.println("\n== JMOD files with jmod");
tool("jmod", none, "create", "--class-path", "water/", "water.jmod");
tool("jmod", none, "describe", "water.jmod");
tool("jmod", List.of(".class"), "list", "water.jmod");
System.out.println("\n== A custom runtime image with jlink");
tool("jlink", none, "--module-path", "mods/", "--add-modules", "garden.plants", "--output", "gardenApp/");
Path image = root.resolve("gardenApp");
System.out.println(" bin, lib and conf folders: " + (Files.isDirectory(image.resolve("bin"))
&& Files.isDirectory(image.resolve("lib")) && Files.isDirectory(image.resolve("conf"))));
Files.readAllLines(image.resolve("release")).stream()
.filter(l -> l.startsWith("MODULES="))
.forEach(l -> System.out.println(" release file: " + l));
runImage(none, "--list-modules");
runImage(none, "-m", "garden.plants/garden.plants.care.Schedule");
} finally {
deleteTree(root);
}
}
}
Output:
== Build (output hidden)
javac ... ok
jar ... ok
javac ... ok
jar ... ok
javac ... ok
jar ... ok
== Describe modules with jar
$ jar -f mods/garden.plants.jar -d
garden.plants jar:file:///<tmp>/mods/garden.plants.jar!/module-info.class
exports garden.plants.care
requires garden.water
requires java.base mandated
contains garden.plants.notes
$ jar --file kiosk.jar --describe-module
No module descriptor found. Derived automatic module.
kiosk automatic
requires java.base mandated
contains kiosk.core
== Dependencies with jdeps
$ jdeps -s kiosk.jar
kiosk.jar -> java.base
kiosk.jar -> java.logging
kiosk.jar -> java.sql
kiosk.jar -> jdk.unsupported
$ jdeps --jdk-internals kiosk.jar
kiosk.jar -> jdk.unsupported
kiosk.core.Ticketer -> sun.misc.Unsafe JDK internal API (jdk.unsupported)
sun.misc.Unsafe See https://openjdk.org/jeps/260
$ jdeps -summary --module-path mods/ mods/garden.plants.jar
garden.plants -> garden.water
garden.plants -> java.base
== JMOD files with jmod
$ jmod create --class-path water/ water.jmod
$ jmod describe water.jmod
garden.water
exports garden.water
requires java.base mandated
$ jmod list water.jmod
classes/module-info.class
classes/garden/water/Sprinkler.class
== A custom runtime image with jlink
$ jlink --module-path mods/ --add-modules garden.plants --output gardenApp/
bin, lib and conf folders: true
release file: MODULES="java.base garden.water garden.plants"
$ gardenApp/bin/java --list-modules
garden.plants
garden.water
java.base
$ gardenApp/bin/java -m garden.plants/garden.plants.care.Schedule
Beds watered
Schedule ready
Points to notice:
jar -don the module JAR listed the unexported package ascontains garden.plants.notes. On the plainkiosk.jarit derived an automatic module namedkiosk.jdeps -sfound four modules, includingjdk.unsupportedbecause ofsun.misc.Unsafe, and--jdk-internalspinpointed the class responsible.jdepsneeded--module-path mods/to analyzegarden.plants, because that module requiresgarden.water.jmod listshows that a JMOD keeps classes under aclasses/prefix. It's a different format from a JAR.- The
releasefile of the runtime image lists exactly three modules, and that image's ownjavaran the program.
Common questions
Which command should I use to describe a module, java or jar?
Either. Both accept -d / --describe-module. With java you name a module found on the module path. With jar you name the JAR file with -f.
Does jdeps need the code to be modular?
No. Analyzing plain JARs before migration is its main use.
Can a jlink image run on another operating system?
No. An image contains native executables for the platform it was built for (or the platform of the jmods used). Build one image per target platform, and the same applies to jpackage.
Is the JDK's java.se module special?
It contains no code. It requires transitive all the standard java. modules, so requires java.se; pulls in the whole Java SE API.
Summary
javamodules are standard, andjdkmodules are JDK-specific.java.baseis required implicitly.java -d/--describe-module,java --list-modulesandjava --show-module-resolutioninspect modules.jar -ddescribes a module JAR.jdepsreports real dependencies:-s/-summary,--jdk-internals/-jdkinternals, and--module-pathwith no short form.jmodhandles JMOD files (create, extract, list, describe, hash).jlink -p ... --add-modules ... --output ...builds a runtime-image folder.jpackagebuilds a native installer for modular or non-modular apps.
Practice quiz
Test yourself with the module commands quiz: 10 exam-style questions with explanations.
Previous: Java Module Services: Service Provider Interface, ServiceLoader, uses and provides (OCP 21)
Next: Java Named, Automatic and Unnamed Modules: Migration Strategies (OCP 21)
Related reading
- Java Module Services: Service Provider Interface, ServiceLoader, uses and provides (OCP 21)
- Java Module Declarations: requires, requires transitive, exports and opens (OCP 21)
- Java Modules: Benefits, module-info.java, Compiling, Running and Packaging (OCP 21)
- User Authentication with JAAS in Java: Login Modules, Callbacks and Subjects
- Java Resource Bundles: Properties Files, Lookup Order, MessageFormat and Properties (OCP 21)

More in OCP Java 21
OCP Java 21 Mock Exam 3 (1Z0-830)
The third full 50-question mock exam for the OCP Java SE 21 Developer exam (1Z0-830), weighted toward the hardest areas: streams, concurrency, generics, modules and I/O. 120 minutes, 68% to pass, with explanations.
OCP Java 21 Mock Exam 2 (1Z0-830)
The second full 50-question mock exam for the OCP Java SE 21 Developer exam (1Z0-830): new questions on every objective, with more multi-select. 120 minutes, 68% to pass, with an explanation for every answer.
OCP Java 21 Mock Exam 1 (1Z0-830)
A full 50-question mock exam for the OCP Java SE 21 Developer exam (1Z0-830), covering every objective at exam difficulty. 120 minutes, 68% to pass, with an explanation for every answer.
Quiz: Final Review (OCP 21)
Ten exam-style questions mixing the most-tested OCP Java 21 rules from the final checklist: promotion, String immutability, overloading, initialization order, collections, streams, exceptions and switch patterns, with explanations.
Discussion
Sign in to ask a question or share what you learned.