jlink)| Directive | Meaning |
|---|---|
requires | this module depends on another module |
exports | makes a package visible to other modules |
requires transitive | dependency is passed along to modules that require this one |
opens | allows reflective access (e.g. for frameworks) to a package |
Turning a plain app into a module is mostly about project layout: put a module-info.java at the source root, keep classes in a package, and declare what the module needs (requires) and shares (exports).
The JVM builds a graph of all module dependencies at startup and verifies it's consistent (no missing or conflicting modules) before your program even starts running — catching configuration errors early.
Non-code files (images, config, properties) can live alongside module code and be loaded via Class.getResourceAsStream(), respecting the module's encapsulation rules.
jlink creates a minimal, self-contained Java runtime image containing only the modules your app actually needs — much smaller than shipping the full JDK, great for containers and embedded devices.
Modules can declare that they provide an implementation of a service interface, and other modules can discover implementations at runtime via ServiceLoader — a plug-in style architecture built into the platform.