Created
March 31, 2020 10:05
-
-
Save agarciadom/d032f9b776bdc87f1e99cd48e8a106f1 to your computer and use it in GitHub Desktop.
Some notes on repackaging JavaFX apps as standalone, trimmed + redistributable JREs:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Adapted from here, tested on a Windows machine: | |
https://www.baeldung.com/jlink | |
First, compile your JavaFX program as usual in Eclipse. Drop the "requires junit;" requirement if you have it - it should be fine as long as your test classes are in the src-test source folder, and the src-test source folder compiles .java files into bin-test (instead of bin). Your test classes will temporarily not compile, but you can restore that line after you are done with this. | |
Note down where you have installed JavaFX: we'll call it $JAVAFX_HOME. | |
Note down where you have installed your JDK: we'll call it $JDK_HOME. | |
Make sure your program works first. Open a terminal, "cd" to the folder of your project, then run: | |
java --module-path bin;$JAVAFX_HOME\lib --module your.module.name/your.main.class | |
You can find out your module name by checking the first line of your module-info.java file. | |
If that works, then you can generate a custom JRE you can redistribute, together with a launcher.bat that runs your Java program, like this (all in one line): | |
jlink --module-path bin;$JAVAFX_HOME\lib;$JDK_HOME\jmods --add-modules your.module.name | |
--launcher launcher=your.module.name/your.main.class | |
--output yourProgramName | |
That will create a "yourProgramName" directory with a custom JRE. You can try to run the main launcher.bat file inside the bin folder, but that will still not work as it is missing the JavaFX DLLs. | |
You need to copy all the .dll files from $JAVAFX_HOME\bin into the bin folder of "yourProgramName", and then it should work. | |
If you do not use the embedded browser component of JavaFX, you may be able to remove the large 60+MB jfxwebkit.dll file from yourProgramName\bin without any issues. | |
Once it works, congratulations! You can zip up that folder and it will run from any Windows machine, without having to install Java. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment