Part 15 / Topic 5 of 7
A short note on JPMS modules
The Java Platform Module System (JPMS, Java 9+) groups packages into modules, each with its own module-info.java declaring exactly what it needs (requires) and what it makes available to others (exports). Everything in this course so far has run on the unnamed module (no module-info.java at all) — perfectly fine for application code, and exactly what Maven's default jar layout still produces unless you add one yourself.
Think of a shipping manifest for a container, versus just throwing boxes on a ship: a module says exactly what's inside and what it needs to function, instead of trusting the whole classpath to sort itself out at runtime.
// module-info.java
module com.acme.report {
requires java.net.http; // this module needs the JDK's HTTP client module
exports com.acme.report; // this module's com.acme.report package is visible to other modules
}
Compiling and running a modular project uses --module-source-path and --module-path instead of a plain classpath:
$ javac -d out --module-source-path src $(find src -name "*.java")
$ java --module-path out --module com.acme.report/com.acme.report.Main
running as module: com.acme.report
declared requires: java.net.http, used here as HTTP_2
$ java --module-path out --describe-module com.acme.report
com.acme.report file:///.../out/com.acme.report/
exports com.acme.report
requires java.net.http
requires java.base mandated
(the two requires lines can print in either order run-to-run — --describe-module does not guarantee ordering among a module's requires entries; exports/contains lines are stable.)
requires java.base mandated is always there — java.base (every class this course has used since Part 1: String, List, Exception, and friends) is implicitly required by every module, no requires line needed for it.
Why this course doesn't build on JPMS further: modules add real value for large, multi-team codebases that want the compiler to enforce "team A's internals are not team B's business" — exactly the strong encapsulation a plain classpath can't express. A small CLI tool or the size of project this course builds doesn't hit that problem, which is why Maven's default (unnamed module, no module-info.java) is the right choice here, and in most real small-to-medium projects.
🔍 Going deeper:
jdeps --print-module-deps(section 2) is JPMS-adjacent even for an unnamed-module jar — it's answering "if I did modularize this, which modules would itrequires?", which is exactly the inputjlink(building a custom, trimmed JVM runtime image) needs.
Full project: examples/jpms-demo/ (src/com.acme.report/module-info.java and .../com/acme/report/Main.java).
Done here? The practice set for Part 15 — including the solutions — is on the part page.