SoFunction
Updated on 2025-03-04

How to package a project into a Windows executable file exe

To package a JavaFX project as.exeFiles, 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)

jpackageis 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

usejpackageCommand to create.exedocument. 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.exedocument.
  • --name YourAppName: Specifies the generated.exeThe 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 (includingmainfully qualified name of method).

Output

  • After executing the command,jpackageA will be generated in the current directory.exeFiles can be used directly for deployment on Windows.

Notice:

  • jpackageAvailable 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)

Launch4jis a popular tool that can encapsulate JAR files into Windows.exedocument.

step:

Download and install Launch4j

accessLaunch4j official websiteDownload and install.

Create a configuration file

  • start upLaunch4j, create a new configuration file. You need to set the following information:
    • Output file: Specify the output.exeFile path.
    • Jar: Select the JAR file you have packaged.
    • Main class: Specify the inclusionmainThe 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).

Generate .exe files

  • After the configuration is complete, click the "Build wrapper" button.Launch4jWill generate a.exedocument.

Attached JRE (optional)

  • If you want users to run applications without installing JRE, you can choose to.exePackage JRE in the file. You canLaunch4jSpecify 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 Setupis a tool for creating installers that can package JavaFX applications with JRE into an executable installer, including.exedocument.
  • useLaunch4jorjpackagecreate.exedocument.
  • useInno SetupCreate the installation package and.exePackage with JRE.

Inno Setup Official Website:/

Among these three methods,jpackageIt is a tool that comes with JDK and is recommended for new versions of JDK;Launch4jis a lightweight tool suitable for all versions of JDK. If you need more features or want to create an installation package,Inno SetupIt 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!