Course contentsShow
← Java
Lesson 2548 of 2,87047. Java Platform Module System (JPMS)Free lesson

Creating a Minimal Runtime Image

Building a custom JRE with only java.base and your application module, drastically reducing distribution size.

Creating a Minimal Runtime Image

What you'll learn: How to use jlink to build a drastically smaller custom JRE containing only java.base and your application module, significantly reducing distribution size.

The Core Idea

By default, a full JRE includes hundreds of modules—most of which your application never touches. With jlink, you can create a minimal runtime image that contains only the absolute essentials: the foundational java.base module and your own application module. This is like packing for a trip with just the clothes you'll actually wear, rather than bringing your entire wardrobe.

For simple applications that don't need GUI frameworks, XML processing, SQL databases, or other platform services, you can achieve runtime images of just 30-50 MB instead of 200+ MB.

Building the Minimal Image

The key is explicitly listing only the modules you need:

jlink --module-path $JAVA_HOME/jmods:mods \
      --add-modules java.base,com.myapp \
      --output minimal-runtime

This command:

  • Uses your module path (mods) where your compiled module resides
  • Includes only java.base (core Java classes) and your com.myapp module
  • Produces a standalone JRE in the minimal-runtime directory

What Gets Included

java.base provides:

  • java.lang (Object, String, System, etc.)
  • java.util (Collections, streams)
  • java.io and java.nio (I/O operations)
  • Basic concurrency, reflection, and annotations

If your application imports anything beyond these—like java.logging or java.net.http—you must add those modules explicitly, or your application will fail at runtime.

Distribution Benefits

Your minimal-runtime directory is a complete, self-contained Java runtime. Ship it with your application, and users don't need Java installed. The reduced size means faster downloads, smaller Docker images, and lower storage costs.

Key Takeaway: A minimal runtime image with only java.base and your module creates the smallest possible distributable JRE, ideal for simple applications where startup size matters more than comprehensive platform features.