How To Deploy JAR, exe and msi for JavaFX 17 Application on Windows 11 x64 (Updated)

Опубликовано: 04 Октябрь 2024
на канале: Ken
3,027
55

In this tutorial, I will show you how to use the JPackage to produce a self-contained JavaFX 17 application includes all the necessary dependencies. It allows us to produce a native package in an .exe or msi on Windows 11 x64.

The tool has options that allow packaged applications to be customized in various ways.

--type
The type of package to create

--input
Path of the input directory that contains the files to be packaged

--dest
Path where generated output file is placed

--main-jar
The main JAR of the application containing the main class

--main-class
Qualified name of the application main class to execute.

--module-path
The path to modular jars

--add-modules
Add list of modules

--win-shortcut
Creates a desktop shortcut for the application.

--win-menu
Adds the application to the system menu.

--description
Description of the application

--app-version
Version of the application and/or package

--icon
Path of the icon of the application package

--jlink-options --bind-services
Includes the available service providers that contains the application's main module and all of its dependencies.

Source:
https://docs.oracle.com/en/java/javas...

You should download and install the following:

JDK 17.0.1 is available from https://www.oracle.com/java/technolog...
Open JavaFX (OpenJFX) and JMODS 17.0.1 are available from https://gluonhq.com/products/javafx/
Java Scene Builder 17.0.0 is available from https://gluonhq.com/products/scene-bu...
IntelliJ IDEA Community Edition 2021.3 is available from https://www.jetbrains.com/idea/download/
WiX Toolset v3.11.2 is available from https://wixtoolset.org/releases/

The Installed directories are as following:

C:\Program Files\Java\jdk-17.0.1
C:\Program Files\Java\javafx-sdk-17.0.1
C:\Program Files\Java\javafx-jmods-17.0.1
C:\Users\Ken\AppData\Local\SceneBuilder
C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.3
C:\Program Files (x86)\WiX Toolset v3.11

VM options
--module-path "C:\Program Files\Java\javafx-sdk-17.0.1\lib"
--add-modules javafx.controls,javafx.fxml

JDK 17.0.1
JavaFX 17.0.1
JavaFX SceneBuilder 17.0.0
IntelliJ IDEA 2021.3
Windows 11 x64

JPackage commandjpackage --input . --main-jar JavaFXHelloWorld.jar --main-class com.example.javafxhelloworld.App --module-path "C:\Program Files\Java\javafx-jmods-17.0.1" --add-modules javafx.controls,javafx.fxml

The following defaults are applied:
The default type of package generated is exe.
The name of the package generated is App-1.0.exe.
The package is written to the current directory.
The main JAR of the application containing the main class is JavaFXHelloWorld.jar
The name of the application main class to execute is com.example.javafxhelloworld.App.
The path to modular jars is "C:\Program Files\Java\javafx-jmods-17.0.1".
The name of added list of modules are javafx.controls,javafx.fxml.
The runtime packaged with the application is generated as part of the packaging process.
The application is installed in the c:\Program Files\App directory.
The name of the launcher is App.exe.
The default icon is used for the application.
No shortcut is created, and the application is not added to any menu. The user must go to the directory in which the application is installed to run it.
No default arguments or Java runtime options are passed to the application when
it is started.

jpackage --type exe --input . --dest . --main-jar .\JavaFXHelloWorld.jar --main-class com.example.javafxhelloworld.App --module-path "C:\Program Files\Java\javafx-jmods-17.0.1" --add-modules javafx.controls,javafx.fxml

The following are also applied:
The default type of package generated is exe.
The package is written to the current directory.

jpackage --type exe --input . --dest . --main-jar .\JavaFXHelloWorld.jar --main-class com.example.javafxhelloworld.App --module-path "C:\Program Files\Java\javafx-jmods-17.0.1" --add-modules javafx.controls,javafx.fxml --win-shortcut --win-menu --icon "icon.ico" --name "My App"

The following are also applied:
The default type of package generated is exe.
The package is written to the current directory.
the description of the application is "My App"

jpackage --type msi --app-version "2.0" --input . --dest . --main-jar .\JavaFXHelloWorld.jar --main-class com.example.javafxhelloworld.App --module-path "C:\Program Files\Java\javafx-jmods-17.0.1" --add-modules javafx.controls,javafx.fxml --win-shortcut --win-menu --icon "icon.ico" --name "My App" --jlink-options --bind-services

The following are also applied:
The default type of package generated is msi.
The package is written to the current directory.
the description of the application is "My App"
The packaging tool generates a runtime image based on the packages or modules that your application needs with the --jlink-options option and passing it the --bind-services jlink option.