
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the JLink tool in Java 9?
What is JLink?
Java Linker 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 the 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 Options
Below are some of the JLink options:
--add-modules mod [,mod...]
The above adds the specified modules (mod) to the current set of root modules, which is empty by default.
--bind-services
It basically tells Java to automatically find and use services (like plugins or tools) that are provided by other modules at runtime.
--compress={0|1|2}
This option sets how much the files in a custom runtime image should be compressed. Here, 0 means no compression, 1 means some compression, 2 means ZIP compression.
--help
It will help in printing the help message.--disable-plugin pluginname
The above option disables the specified plugin(plugin name).
Creating a Custom JRE
To create a custom JRE, we will be using the JLink tool by using the following command:
jlink --module-path --add-modules --limit-modules --output
Here,
- module-path is the path where observable modules have discovered by the linker. It can be modular JAR files, JMOD files, and modules.
- add-modules names the modules to add to the run-time image, these modules can, via transitive dependencies, cause additional modules to be added.
- limit-modules limits the universe of observable modules.
- the output is the directory that contains the resulting run-time image.
Example
In the above command, the value of 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 contains the artifact for module com.greetings.
jlink --module-path $JAVA_HOME/jmods:mlib --add-modules com.greetings --output greetingsapp