Sub topic 8
What is inside the image
This chapter assumes you can build an image with jlink (the previous chapter) and know what a module descriptor is. Here you will look at the directories and files that jlink produces, and learn what each one is for.
The top-level layout
A runtime image is an ordinary directory. After the build from the previous chapter, list it:
ls build/runtimeYou will see these entries on Linux and macOS:
| Entry | Purpose |
|---|---|
| `bin` | Executables: `java`, plus any launchers you asked for |
| `conf` | Configuration files, such as security and logging settings |
| `lib` | The runtime itself: the module image, native libraries, and support files |
| `release` | A small text file describing the image |
| `legal` | License files for the included modules |
| `include` | JNI header files (absent with `--no-header-files`) |
| `man` | Manual pages (absent with `--no-man-pages`) |
The include and man directories are the ones the size options in a later chapter remove. The rest stay in every image.
The bin directory
bin always holds a java executable. It is the same launcher you know from a full JDK, but it can only start the modules that are in this image. If you built with --launcher hello=..., bin also holds a hello script. The script calls the image's java with the module and main class already filled in.
Tools such as javac and jar are not copied unless you add the modules that contain them (jdk.compiler, jdk.jartool). Most images do not need them.
The lib directory
The most important file in lib is called modules. It holds the classes of every module in the image, stored in a single packed file that the JVM reads directly. Your application's classes are in this file as well, because jlink treats your module like any JDK module. This is why the image does not need your mods/app.jar after it is built.
lib also contains the JVM itself (in lib/server), native libraries such as libjava.so, and lib/jrt-fs.jar.
The release file
The release file is plain text with one KEY="value" pair per line. Read it with:
cat build/runtime/releaseTypical entries include JAVA_VERSION, MODULES (the list of modules in the image), OS_NAME, and OS_ARCH. Deployment scripts can read this file to check which Java version and platform an image was built for, without starting the JVM.
How the pieces fit together
Confirming what is in the image
You can check the module contents two ways. The MODULES line in release is a record written at build time. The command below asks the image's own runtime, so it reflects what is actually present:
build/runtime/bin/java --list-modulesFor an application that requires only java.logging, the list is short: com.example.app, java.base, and java.logging.
The sizes tell the same story. Compare a full JDK with the image:
du -sh "$JAVA_HOME" build/runtimeThe full JDK is typically several hundred megabytes. A minimal image is a small fraction of that.
Exercise
You built an image and then deleted mods/app.jar. Does build/runtime/bin/hello still work, and why?
Show answer
Yes. jlink copied your application's classes into the image's lib/modules file, so the image does not depend on the original JAR.
Exercise
Name two ways to find out which modules an image contains, and say how they differ.
Show answer
Read the MODULES line in the release file, or run bin/java --list-modules. The first is metadata recorded at build time. The second asks the image's own runtime, so it shows what is actually installed.