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

Prerequisites for Using jlink

Requirements for jlink: fully modular applications, module-info.java declarations, and modular dependencies.

Prerequisites for Using jlink

You'll learn what conditions must be met before you can successfully create custom runtime images with jlink.

The Foundation: Fully Modular Applications

Think of jlink as a precision tool that only works with well-defined building blocks. Before you can create a custom runtime image with jlink, your application must be fully modular. This means every component—your application code and all its dependencies—must be explicit modules, not automatic modules or classpath-based JARs.

What "Fully Modular" Really Means

To use jlink successfully, you need:

1. Proper module-info.java declarations: Every module in your application graph must have a module-info.java file that explicitly declares its dependencies with requires directives and its exports with exports directives.

2. Modular dependencies: All libraries your application depends on must be modular JARs (containing their own module-info.class). Automatic modules are not sufficient—jlink cannot process them because they lack the strong contracts that explicit modules provide.

3. Clean module graph: Your module declarations must form a valid, complete dependency graph with no missing edges. Run jdeps beforehand to validate your module structure.

Why These Requirements Exist

jlink works by analyzing the module graph to determine exactly which platform modules and classes are needed. Without explicit module-info declarations everywhere, jlink cannot safely determine what to include or exclude. Automatic modules have fuzzy boundaries (they "require all" and "export all"), making them incompatible with jlink's precision approach.

If your application still uses automatic modules or classpath JARs, you must first complete the migration to explicit modules before jlink becomes available to you.

Key Takeaway: jlink requires a fully modular application where every component has an explicit module-info.java declaration, and all dependencies are proper modular JARs—automatic modules and classpath-based libraries cannot be processed by jlink.