Home > Java > javaTutorial > JEP package tool in Java

JEP package tool in Java

王林
Release: 2023-09-14 17:21:24
forward
1463 people have browsed it

JEP package tool in Java

JEP, or Java Enhancement Proposal, are ideas for enhancing the Java platform. The JEP packaging tool is one such improvement that enables programmers to package Java programs into native executable files.

Developers can create native executables from Java programs by implementing the JEP Package Tool. Doing so gives these executables independence, eliminating dependence on the Java Virtual Machine (JVM) or other related software components. The emergence of this powerful tool started with Java 14, where it was introduced as an experimental feature.

Syntax for using JEP package tools

The syntax of the JEP package tools is easy to read and understand. Use JEP packaging tools. JDK 14 must be installed on your computer. Since this tool works through command line. Using it requires opening a terminal window or command prompt. This is the syntax for the JEP package tool -

jpackage [options]
Copy after login

The [options] field provides various parameters that you can use to modify the behavior of the JEP Package Tool. Optional and required options can be divided into two groups.

The options are as follows:

  • --name - The name of the package.

  • --input - The input directory containing the application files.

  • --main-jar − The name of the main JAR file.

  • --main-class − The name of the main class.

  • --type − Type of package (for example, exe, msi, deb, rpm).

  • --output − The name of the output file.

  • --vendor − The name of the vendor.

  • --copyright - Copyright statement.

  • --description - Description.

  • --resource-dir - Directory containing resources.

How to use JEP package tool

Follow the following steps to use the JEP packaging tool -

  • Step 1 - Install Java 14 or later

    The only requirement to use the JEP Package Tool is to install Java 14 or later. Therefore, if your device lacks this version of the Java software installed; it must be installed to access the tool.

  • Step 2 − Create a Java application

    In order to package a Java application as a local executable, create it. You can use non-modular applications or modular applications.

  • Step 3 - Compile the application

    Compile the program using the Java compiler

  • Step 4 - Create package

    Once the program is built, you can use the JEP Package tool to generate a native executable package. In order to achieve this, you must provide the name of the module and the location of the output file.

    The following is an example command to use the JEP Package tool to generate a native executable package -

jpackage --name MyApplication --input target/modules --main-jar MyApp.jar --main-class com.example.MyApp --type exe --output MyApplication.exe
Copy after login

For this particular example, the software used bears the name "MyApplication" and operates through a central JAR file appropriately titled "MyApp.jar". Access to data input can be found in the specified directory labeled "target/modules". Additionally, the name of the main class component that the program operates on is "com.example.MyApp". The final product generated using such a process will have relevant information in an output file labeled "MyApplication.exe", which is designed within the scope of a package structure designated as an executable ("exe") format.

Different ways to use attributes in Servlets

There are several ways to use the JEP packaging tool, depending on the specific requirements of your application.

Method 1: Pack only one JAR file

If your program consists of just a JAR file, then the JEP package tool is your best choice, allowing you to generate a self-sufficient executable file. especially. This executable does not require a different JRE to be installed on any machine to run. For example -

jpackage --input /path/to/myapp.jar --main-jar myapp.jar
Copy after login

Use this command to generate an autonomous executable file. It will generate a file called myapp which can be easily executed on any computer.

Method 2: Pack multiple files into one directory

Developers dealing with multiple distributed resources and configuration files or different libraries should choose the JEP package tool, which provides an efficient solution. With this tool, it is possible to generate an all-inclusive executable package that contains all necessary content.

jpackage --input /path/to/myapp --main-jar myapp.jar
Copy after login

This command will create a self-contained executable file named myapp that contains all files in the /path/to/myapp directory.

Method 3: Generate executable files for multiple platforms

To create a platform-specific executable file, such as an EXE file for Windows or a DMG file for macOS, you can take advantage of the JEP Package Tool's --type option. Here are some command examples -

jpackage --input /path/to/myapp --main-jar myapp.jar --type exe
Copy after login

This particular command has the ability to generate Myapp.exe - a completely self-contained and highly adaptable executable created specifically for use in a Windows environment.

jpackage --input /path/to/myapp --main-jar myapp.jar --type dmg
Copy after login

This command will generate a self-contained executable file Myapp.dmg that can be executed on macOS.

JEP软件包工具的高级功能

此外,JEP 包工具还提供了许多复杂的功能,可用于进一步定制包。这是一些插图 -

创建自定义启动画面

要为您的程序提供独特的启动屏幕,请使用 --splash 选项。命令示例如下 -

jpackage --input /path/to/myapp --main-jar myapp.jar --splash splash.png
Copy after login

此命令将生成一个独立的可执行文件,该文件具有名为splash.png的独特启动屏幕。

签署包裹

要使用证书对包进行签名,请使用 --sign 选项。命令示例如下 -

jpackage --input /path/to/myapp --main-jar myapp.jar --sign mycert
Copy after login

该程序将生成一个独立的可执行文件,该文件已签名并具有一个名为 mycert 的证书,名为 myapp。

合并 JVM 选择

启动程序时,您可以使用 --java-options 选项包含 JVM 参数。命令示例如下 -

jpackage --input /path/to/myapp --main-jar myapp.jar --java-options "-Xmx512m -Dmyprop=value"
Copy after login

JVM 选项 -Xmx512m 和 -Dmyprop=value 将包含在此命令生成的独立可执行文件中。

结论

JEP Package Tool 是一个强大的工具,可以让开发人员轻松地将 Java 程序打包成独立的可执行文件。 JEP 包工具可用于生成特定于特定平台的可执行文件,使用独特的启动屏幕和签名自定义包,并凭借其简单的语法和复杂的功能将 JVM 参数添加到应用程序的运行时。开发人员可以利用 JEP 包工具使 Java 应用程序更易于使用和访问,而无需安装单独的 JRE。

The above is the detailed content of JEP package tool in Java. 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