Home >Java >javaTutorial >What is the purpose of using JLink in Java 9?

What is the purpose of using JLink in Java 9?

王林
王林forward
2023-08-29 11:45:021303browse

The main purpose of the

在Java 9中使用JLink的目的是什么?

JLink function is to create our own customized JRE. Typically, we use the default JRE provided by Oracle Corporation to run the program, with a size of 214 MB .

For example, the user wants to print a simple "Hello World" message as shown below

public class HelloWorldModuleTest {
   public static void main(String args[[]) {
      System.out.println("Hello World!");
   }
}

To run the above 1 KB size program, we need 4 – 5 classes, for exampleString, System, Object and HelloWorldModuleTest.class files. So why do we need to use the default JRE to load a 214 MB JRE? This is a waste of memory and not suitable for any IoT device as these small devices cannot fit hundreds of memory.

We need to create our own custom JRE using JLink in the command below.

<strong>jlink &ndash;module-path out &ndash;add-modules {add modules} &ndash;output {jre name}</strong>

JLink is a powerful feature implemented with the help of JPMS to reduce the size of the JRE. JLink has the concept of compression, and we specify the compression level when executing the JLink command. JLink also provides an option called Launcher that allows the user to execute a program from anywhere on the computer by simply calling the program name from the Command Line Prompt without having to specify java or javac.

The above is the detailed content of What is the purpose of using JLink in Java 9?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete