Chapter 13. Scaling Down with Custom Runtime Images

Now that you’ve seen all the tools and processes to work with modular applications, there’s one more exciting opportunity to explore. In “Linking Modules”, you got a taste of creating runtime images tailored to a specific application. Only the modules required to run the application become part of the image. A minimal runtime image can be automatically generated with jlink by using explicit dependency information available in modules.

Creating a custom runtime image is beneficial for several reasons:

Ease of use

jlink delivers a self-contained distribution of your application and the JVM, ready to be shipped.

Reduced footprint

Only the modules that your application uses are linked into the runtime image.

Performance

A custom runtime potentially runs faster by virtue of link-time optimizations that are otherwise too costly or impossible.

Security

With only the minimum required platform modules in a custom runtime image, the attack surface decreases.

Even though creating a custom runtime image is an optional step, having a smaller binary distribution that runs faster is a compelling motivation—especially when applications target resource-constrained devices, such as embedded systems; or, when they run in the cloud, where everything is metered. Putting a custom runtime image into a Docker container is a good way to create resource-efficient cloud deployments.

Tip

Other initiatives are improving Java’s support ...

Get Java 9 Modularity now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.