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.
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]
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
--input
--main-jar
--main-class
--type
--output
--vendor
--copyright
--description
--resource-dir
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
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.
There are several ways to use the JEP packaging tool, depending on the specific requirements of your application.
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
Use this command to generate an autonomous executable file. It will generate a file called myapp which can be easily executed on any computer.
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
This command will create a self-contained executable file named myapp that contains all files in the /path/to/myapp directory.
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
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
This command will generate a self-contained executable file Myapp.dmg that can be executed on macOS.
此外,JEP 包工具还提供了许多复杂的功能,可用于进一步定制包。这是一些插图 -
要为您的程序提供独特的启动屏幕,请使用 --splash 选项。命令示例如下 -
jpackage --input /path/to/myapp --main-jar myapp.jar --splash splash.png
此命令将生成一个独立的可执行文件,该文件具有名为splash.png的独特启动屏幕。
要使用证书对包进行签名,请使用 --sign 选项。命令示例如下 -
jpackage --input /path/to/myapp --main-jar myapp.jar --sign mycert
该程序将生成一个独立的可执行文件,该文件已签名并具有一个名为 mycert 的证书,名为 myapp。
启动程序时,您可以使用 --java-options 选项包含 JVM 参数。命令示例如下 -
jpackage --input /path/to/myapp --main-jar myapp.jar --java-options "-Xmx512m -Dmyprop=value"
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!