Tool creation with JavaFX & self-contained package (distribution)

About this page

When you want a tool in a project, Excel macros are still on the business trip in the SI area, It's heavy and difficult to maintain, and I wonder if there is anything else. I will try it as a Java client application and summarize the procedure.


What is a self-contained package?

The bottleneck of Java client applications is that they require a Java execution environment for the device to be started. Then, it works or does not work due to the version difference for each terminal. This is not popular. Therefore, JRE is also installed in the distribution application so that the application can refer to it. Now you can run the app regardless of the environment on the device side. This will be popular.


Execution environment

environment service/version
Execution environment Windows10
Development environment eclipse 4.11.0
application JavaFXapplication on Java11

Step 1. Export application to jar

This time, I will export from the GUI of eclipse. Right click on the project ⇒ select Export

Select the executable jar and proceed to the next file specification setting. When you press Finish, the lib folder containing the executable jar and the dependency jar will be output.

A folder with the executable jar and external libraries has been created. 無題.png


Step 2. Create a JRE for your app

Next, prepare the JRE referenced by the executable jar created in step 1. Even if you copy the JRE used in eclipse as it is, it will work, but Since it is for distribution, my motivation is to keep it in the minimum necessary size.


First, check what you need to pack. Just check the dependencies of the created module, You can check it with the jdeps command (added since JDK 8).

jdeps --module-path "* Enter the JRE path used to create the application *\pleiades\java\11.0.2\lib" -s * Created jar *.jar

Since I created a JavaFX application this time, it looks like the following.

LDAtool.jar -> java.base
LDAtool.jar -> javafx.base
LDAtool.jar -> javafx.controls
LDAtool.jar -> javafx.fxml
LDAtool.jar -> javafx.graphics
LDAtool.jar ->Not found
javafx.base -> java.base
javafx.base -> java.desktop
javafx.controls -> java.base
javafx.controls -> javafx.base
javafx.controls -> javafx.graphics
javafx.fxml -> java.base
… (Omitted below)

When converting to JRE, be aware of only the parts that have a direct dependency on the jar. This time, the following applies.


Give these modules to the jlink command and execute as follows. You now have a JRE dedicated to the distribution application called jre-min.

jlink --compress=2 --module-path "* Enter the JRE path used to create the application *\pleiades\java\11.0.2\jmods" --add-modules java.base,javafx.base,javafx.controls,javafx.fxml --output jre-min

Step 3. Make the jar for distribution into an exe

Finally, wrap the jar in exe format so that it can be started by double-clicking in any environment. This time, we used a wrapping tool called Launch4j.

Download / install from here. After setting the following, press the gear icon to execute.


Settings Settings
Outputfile Specify the output destination of the exe file (I want to distribute this time, so JRE(jre-min folder)Specify the same hierarchy as
jar Specify the jar file created in step 1
Bundle JRE Pass Specify the JRE created in step 2 (specify with the relative path of the exe so that it does not depend on the storage location)
Min JRE version Since it seems to be a required item, describe the version of JRE

image.png

image.png


An exe file has been generated. Let's run it. If the application starts, it's successful!

image.png


It is an image to distribute the folder containing the exe and jre created from the above by zipping it.

無題.png


Reference material

Recommended Posts

Tool creation with JavaFX & self-contained package (distribution)
Tool creation with JavaFX & self-contained package (JavaFX edition)
Make a slideshow tool with JavaFX
HelloFX with JavaFX
Merry Christmas with JavaFX !!
CLI creation with thor
Graph creation with JFreeChart