Deploy JavaFX 19 JAR, exe, msi Using Intellj 2022.3.2 on Windows 11 x64 (Full version)

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

This tutorial will take you through the steps of deploying a JavaFX 19 application as an executable jar file using IntelliJ 2022.3.2 on Windows 11 x64. The jar file will include the JavaFX application and all the necessary JavaFX library and DLL (.dll) files, so you can run the application by simply double-clicking the jar.

Furthermore, you will learn how to use JPackage to generate a standalone JavaFX 19 application that contains all required dependencies. The result will be a native package in either .exe or .msi format for Windows 11 x64.

Before you start, you need to download and install the following components:

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

The installation directories for these components are as follows:

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

Step-by-Step Guide for Deploying a JavaFX 19 Application Jar using IntelliJ 2022.3.2 on Windows 11 x64:

1. Download and install the following software:
JDK 19.0.2 from https://www.oracle.com/java/technolog...
Open JavaFX (OpenJFX) and JMODS 19.0.2 from https://gluonhq.com/products/javafx/
Java Scene Builder 19.0.0 from https://gluonhq.com/products/scene-bu...
IntelliJ IDEA Community Edition 2022.3.1 from https://www.jetbrains.com/idea/download/
WiX Toolset v3.11.2 from https://wixtoolset.org/releases/

2. Set the following directories:
Java Installation directory: C:\Program Files\Java\jdk-19
JavaFX Installation directory: C:\Program Files\Java\javafx-sdk-19.0.2.1

3. Set environment variables:
JAVA_HOME="C:\Program Files\Java\jdk-19"
PATH="%JAVA_HOME%\bin"

4. If you are not familiar with setting environment variables, refer to this tutorial:    • How To Install JDK 15.0.2 on Windows ...  

5. Use the following VM options:
--module-path "C:\Program Files\Java\javafx-sdk-19.0.2.1\lib"
--add-modules javafx.controls,javafx.fxml

Leaving a space between the two module names, like this: --add-modules=javafx.controls, javafx.fxml, may result in a syntax error. Therefore, it is important to ensure that there is no space between the module names when using the --add-modules option with JavaFX.

6. Deploy your JavaFX 19 application jar file using IntelliJ 2022.3.2.

7. Use JPackage to produce a self-contained JavaFX 19 application, including all necessary dependencies, in an .exe or .msi file on Windows 11 x64.

The JPackage tool provides options to customize your packaged application 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.

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

JPackage command

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

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-19.0.2.1" --add-modules javafx.controls,javafx.fxml --win-shortcut --win-menu

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

jpackage --type exe --input . --dest . --main-jar JavaFXHelloWorld.jar --main-class com.example.javafxhelloworld.App --module-path "C:\Program Files\Java\javafx-jmods-19.0.2.1" --add-modules javafx.controls,javafx.fxml --win-shortcut --win-menu --icon "icon.ico" --name "My App" --app-version "2.0" --description "JavaFX 19 Hello World App" --verbose

#JavaFX​​19 #ExecutableJar​​ #DeployJar​ #CreateJar