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

What is the purpose of using JLink in Java 9?

王林
Release: 2023-08-29 11:45:02
forward
1335 people have browsed it

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!");
   }
}
Copy after login

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>
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template