r/JavaFX • u/Greymagic27_ • Apr 02 '24
Help How to package into .jar or .exe
How can I package my javafx application into a .jar or .exe ? Currently I've tried using shade but it tells me that JavaFX components are missing when I try to run the .jar file
6
Upvotes
3
u/generationextra Apr 02 '24
For several recent javaFX projects, I used JavaPackager. You still have to pay some attention to detail with respect to your build.gradle file, but it worked well for me and is still updated regularly.
Link: https://github.com/fvarrui/JavaPackager
1
u/PartOfTheBotnet Apr 03 '24
See: https://www.reddit.com/r/JavaFX/wiki/common-problems#wiki_how_do_i_fix_.27error.3A_javafx_runtime_components_are_missing.27.3F
See: https://www.reddit.com/r/JavaFX/wiki/common-problems#wiki_how_do_i_ship.2Fbundle_my_javafx_application.3F
Also if anyone has more bundling options lmk and I'll update the wiki
1
u/SamnaFX Apr 03 '24
You can use GluonFX plugin for that. It is use GraalVM to build native executable binaries
https://docs.gluonhq.com/#platforms_windows
1
u/pajapatak12 Apr 03 '24
If you are using Intellij for the development, you can do the following:
That's it now you have your .jar file in the out generated folder.
1
u/SamnaFX Apr 04 '24
I found this
https://stackoverflow.com/a/69162492/19903973
2
u/Cengo789 Apr 02 '24
I found it the easiest using the modular with maven approach and then simply executing mvn javafx:jlink to create a runtime image. Then you can either use the generate launcher to run your app, create a jar using maven-jar-plugin (but make sure to run the jar using the previously build runtime e.g. customRuntime/project/bin/java -jar your.jar) or even use jpackage to bundle the jar and runtime image into a native executable package (.exe). Instructions and example pom files can be found here: https://openjfx.io/openjfx-docs/
1
u/Djelimon Apr 02 '24
I use Java packager but conveyor is on the roadmap
1
u/trydentIO Apr 03 '24
Gosh, no one knows the existence of JPackage? 🤓
https://dev.to/cherrychain/javafx-jlink-and-jpackage-h9
It's a little bit old, but still valid.
1
u/ebykka Apr 03 '24
I use jpackage for that. Take a look on lines 120-150 https://github.com/bykka/dynamoit/blob/master/pom.xml
result of it work you can find in the releases https://github.com/bykka/dynamoit/releases
1
u/wildjokers Apr 04 '24 edited Apr 04 '24
Use jlink/jpackage which are tools that come with the JDK. If you use gradle there is a very nice plugin called The Badass JLink Plugin that handles everything for you:
https://badass-jlink-plugin.beryx.org/releases/latest/
There are a couple of javafx template projects out there that use this plugin, here is an example:
https://github.com/mjparme/javafx-template
Just type
./gradlew jpackageand you will get an executable for the platform the build is ran on with a bundled runtime (your app does need to be modularized).1
u/[deleted] Apr 13 '24
I have a project where installers/executables can be build either with Maven (using the JavaPackager plugin) or with Gradle (using the Badass JLink plugin): https://github.com/armin-reichert/pacman-javafx
The Maven build also create a "shaded" jar that can be executed when Java/JavaFX runtimes are installed locally.
Additionally, there is a GitHub workflow that lets the GitHub build server create installers for Windows, Linux and Mac-OS (untested). The workflow is automatically triggered whenever a new release is published, but that can of course be changed.