JLink is a new linker tool that has been used to create our own customized JRE. Usually, we can run our program using default JRE provided by Oracle. If we need to create our own JRE then use this tool. JLink tool can help to create its own JRE with only the required class to run the application. It can reduce the size of the API developed and the dependency of using full JRE.
In Java 9, we have a new phase between compiling the code and its execution link time. Link time is an optional phase between the phases of compile-time and runtime.
jlink --module-path --add-modules --limit-modules --output
jlink --module-path $JAVA_HOME/jmods:mlib --add-modules com.greetings --output greetingsapp
In the above command, the value to module-path is a PATH of directories containing the packaged modules. JAVA_HOME/jmods is a directory containing java.base.jmod, other standards, and JDK modules. The directory mlib on the module path containing the artifact for module com.greetings.