What is jlink in Java?

jlink is a command-line tool introduced in Java 9 that allows developers to create custom Java runtime images. These images can include only the necessary components of the Java Runtime Environment (JRE) needed to run a specific application, thereby reducing the size of the deployment and improving startup time. It enables packaging applications with their necessary dependencies in a lightweight manner, making it easier to distribute and manage Java applications.

jlink uses a modular approach to create a runtime image based on the modules that are required for running an application. This helps in creating a reduced footprint of Java applications and optimizes resource usage.

For example, to create a runtime image for an application called "myapp" with the main class "com.example.Main", you would use the following command:

jlink --module-path $JAVA_HOME/jmods:myapp.jar --add-modules com.example --output myapp-image

This command specifies the module path, names the application's module, and sets the output directory for the custom runtime image.


jlink Java Java Runtime Environment modularity custom runtime images application deployment Java applications