Files
asmhatreandClaude Sonnet 5.5 de2660e998 Add jpms-basics module: JPMS for working developers, exports vs opens, split packages, automatic modules, jdeps and jlink on JDK 25
Five modules built with plain javac/java/jdeps/jlink on Temurin 25.0.5.1. Sources, broken/ cases,
run.sh and captured transcripts in output/. README row added.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b4XrpfdpsacrvqnrBM
2026-11-26 20:53:17 +05:30

43 lines
2.4 KiB
Markdown

# jpms-basics
Companion code for the ankurm.com post **Java Modules (JPMS) for Working Developers: module-info, exports, opens and jdeps**
(<https://ankurm.com/java-modules-jpms-module-info-exports-opens-jdeps/>). Plain `javac`, `java`, `jdeps`, `jlink`: no Maven, no Gradle.
The explanation lives in the article (collapsible sections); this folder has the sources, `run.sh` and the captured transcripts in `output/`.
## Tested against
| Thing | Version |
|---|---|
| JDK | Eclipse Temurin 25.0.5.1+2 (JDK 25, LTS, GA 2025-09-16), `output/00-versions.txt` |
| jlink input | the matching Temurin 25.0.5.1+2 `jmods` download (the main Temurin 25 tarball has no `jmods/`, see `output/11b-jlink-without-jmods.txt`) |
## Run it
```bash
export PATH=/path/to/jdk-25/bin:$PATH
export JMODS=/path/to/jdk-25-jmods # only for the jlink step; defaults to $JAVA_HOME/jmods
./run.sh # about 2 minutes; rebuilds build/ and regenerates every file in output/
```
Single scenarios once `run.sh` has built `build/mods`:
```bash
java -p build/mods -m com.acme.app/com.acme.app.Main hello
java -p build/mods -m com.acme.app/com.acme.app.Main reflect-private # InaccessibleObjectException
java --add-opens com.acme.greeter/com.acme.greeter.api=com.acme.app -p build/mods -m com.acme.app/com.acme.app.Main reflect-private
```
## Layout
| Path | What |
|---|---|
| `src/com.acme.model`, `.greeter`, `.formal`, `.mapper`, `.app` | five modules: a record, a library with a hidden package and a service, a provider, a tiny reflective mapper, the app (`Main` has one scenario per argument) |
| `broken/` | sources that must fail: unexported package, missing `requires`, non-transitive `requires`, cycle, split package, empty `exports` |
| `legacy/`, `automatic/` | a pre-module jar (no `module-info`) that names `sun.misc.Unsafe`, and a module that requires it as an automatic module |
| `output/` | captured output, one file per topic (`01` build, `02` describe, `03` compile errors, `04` reflection, `05` opens for frameworks, `06` split packages, `07` class path, `08` services, `09` automatic modules, `10` jdeps, `11` jlink) |
## Notes on the transcripts
Absolute paths are rewritten to `file:///.../jpms-basics/` and the unnamed-module hash to `@<hash>`. The jlink image sizes in `11-jlink.txt` are machine dependent; everything else is byte-stable.
MIT licensed, see the repository `LICENSE`.