jlink: command not found

A new tool, called jlink was introduced in Java 9 that enables the creation of modular runtime images. These runtime images are nothing but a collection of a set of modules and their dependencies. A Java enhancement proposal, JEP 220, governs the structure of this runtime image.

The JLink tool is designed to provide optional phases between compile time and runtime, called link time, which links a set of modules and its transitive dependencies to create runtime images. JLink makes deployment simpler and also reduces the size of an application.

The invocation syntax of jLink is as follows:

jlink --module-path [modulepath] --add-modules [modules] --limit-modules [modules] --output [path]

Here,
–module-path – jLink use module path for finding modules such as modular jars, JMOD files
–add-modules – Mention module which needs to include in default set of modules for run time image, by default set of modules in empty.
–limit-modules – Use this option to limits modules, which is required for our application.
–output – Final resulting run-time image will be stored in output directory
–help – list details about jLink options
–version – show the version number

If you get the below error while running the jlink command:

jlink: command not found

you may install the below package as per your choice of distribution.

Distribution Command
Debian apt-get install openjdk-12-jdk-headless
Ubuntu apt-get install openjdk-9-jdk-headless
Arch Linux pacman -S jdk10-openjdk
Kali Linux apt-get install openjdk-11-jdk-headless
Fedora dnf install java-9-openjdk-devel-debug-1
Raspbian apt-get install openjdk-9-jdk-headless

Conclusion

A new tool in JDK 9 is the jlink command—Java’s linker for creating custom runtime images. You can include just what’s necessary for a given app or set of apps to execute in a custom runtime. For example, if you’re creating a runtime for a device that does not support GUIs, you can create a runtime without the corresponding modules that support Swing and JavaFX.

Related Post