Inspecting Modular JAR Contents with jar --describe-module
You'll learn how to examine the module descriptor and dependencies inside a modular JAR without unpacking it.
What Is This Tool For?
Once you've created a modular JAR (combining compiled classes and a module-info.class), you often need to verify what module information it contains. The jar tool provides a --describe-module option that reads the module descriptor and displays its contents in a human-readable format—like peeking at a package's label before opening it.
The Basic Syntax
jar --describe-module --file mymodule.jar
Or using the short form:
jar -d -f mymodule.jar
What You'll See
This command displays:
- Module name and version (if specified)
- Module dependencies (all
requiresdirectives) - Exported packages (all
exportsdeclarations) - Opened packages (all
opensdeclarations, if any) - Services used (from
usesdirectives) - Services provided (from
provides...withdirectives) - Main class (if one was specified when creating the JAR)
Example Output
com.example.myapp@1.0
requires java.base
requires transitive java.sql
exports com.example.myapp.api
opens com.example.myapp.internal to com.example.framework
provides com.example.spi.DataProvider with com.example.myapp.impl.DataProviderImpl
Why This Matters
You don't need to unpack the JAR or manually read the binary module-info.class. This tool quickly verifies that your module metadata is correct, helps diagnose classpath issues, and confirms dependencies before deployment.
Key Takeaway:
Use jar --describe-module --file <jar-file> to inspect a modular JAR's complete module descriptor, including dependencies, exports, opens, and services, without extracting its contents.