To package a JavaFX project as.exe
Files, you can use some tools to encapsulate your application as a Windows executable. Here are two commonly used methods:
Method 1: Use jpackage (for JDK 14 and later)
jpackage
is a built-in tool in JDK that can package your Java applications into a platform-specific installer or executable file (including.exe
)。
step:
Build a JAR file:
Make sure your JavaFX application has been successfully built into a JAR file (for example)。
Package with jpackage:
usejpackage
Command to create.exe
document. First open a command line tool (such as PowerShell or Command Prompt) and execute the following command:
jpackage --type exe --name YourAppName --input <JAR The directory where the file resides> --main-jar --main-class
explain:
-
--type exe
: Specify the output as.exe
document. -
--name YourAppName
: Specifies the generated.exe
The name of the file. -
--input <Directory where the JAR file is located>
: Specify the directory containing the JAR file. -
--main-jar
: Specify the main JAR file of the application. -
--main-class
: Specify your main class (includingmain
fully qualified name of method).
Output:
- After executing the command,
jpackage
A will be generated in the current directory.exe
Files can be used directly for deployment on Windows.
Notice:
-
jpackage
Available in JDK 14 and later. If you are using a lower version of JDK, please upgrade to JDK 14 or later.
Method 2: Use Launch4j (for all JDK versions)
Launch4j
is a popular tool that can encapsulate JAR files into Windows.exe
document.
step:
Download and install Launch4j:
accessLaunch4j official websiteDownload and install.
Create a configuration file:
- start up
Launch4j
, create a new configuration file. You need to set the following information:-
Output file: Specify the output
.exe
File path. - Jar: Select the JAR file you have packaged.
-
Main class: Specify the inclusion
main
The fully qualified class name of the main class of the method. - JRE: Configure the Java runtime environment (optional, if JRE is not installed, you can specify the JRE path).
-
Output file: Specify the output
Generate .exe files:
- After the configuration is complete, click the "Build wrapper" button.
Launch4j
Will generate a.exe
document.
Attached JRE (optional):
- If you want users to run applications without installing JRE, you can choose to
.exe
Package JRE in the file. You canLaunch4j
Specify the JRE path in the settings, or use tools such asInno SetupCome and pack together.
Method 3: Use Inno Setup (providing support for installation packages)
-
Inno Setup
is a tool for creating installers that can package JavaFX applications with JRE into an executable installer, including.exe
document. - useLaunch4jorjpackagecreate
.exe
document. - useInno SetupCreate the installation package and
.exe
Package with JRE.
Inno Setup Official Website:/
Among these three methods,jpackage
It is a tool that comes with JDK and is recommended for new versions of JDK;Launch4j
is a lightweight tool suitable for all versions of JDK. If you need more features or want to create an installation package,Inno Setup
It can also help you complete this task.
This is the article about how to package Javafx projects into Windows executable file executable file exe. For more related Javafx projects, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!