javajavafxlaunch4jopenjfx

JavaFX project wrapped with Launch4j VM arguments path


For some of my projects I'm using JavaFX for the GUI, and prior to JavaFX being split as OpenJFX I didn't had any problems with it. Now I want to use the latest versions of both JDK and JavaFX, so because of this some changes had to be made.

While working in Eclipse, everything is running as it should, I added JavaFX as a library, but I have some problems when I try to create an exe file from the runnable jar using Launch4j. In Eclipse I'm using 2 VM arguments:

  1. --module-path "Path to the lib folder\" --add-modules javafx.controls,javafx.graphics,javafx.fxml
  1. --add-opens javafx.graphics/com.sun.glass.ui=ALL-UNNAMED

With the second argument I don't have any problems, as it doesn't require a path to a lib, but the first one does, and I can't simply use a static path (like: C:\MyAppName\lib) because the user may install the app where he wants to, and there will be the lib also. That being said, what can I use as a relative path, so Launch4j knows what to do? The lib folder is in the same location as the exe.

I tried the following but with no luck (I've added them in JVM options box):

The question maybe has some details that may not be related to what I need, but maybe someone else has the same problem, and I wanted to add them to maybe help them too when I get an answer.


Solution

  • Following @James_D advice, I actually used jpackage instead of Launch4j and it is better, not only that it creates your exe file, but it also removes the need from the user to install Java by creating a native package in a platform-specific format.

    That being said, this is a small guide on Windows 10 OS on how to use jpackage with a JavaFX project. For more information read the documentation. jpackage is available for macOS and Linux, but I'm using Windows 10, so the guide is specific to it.

    jpackage -t exe --name "Name of app" --app-version 1.0 --input "Location of runnable Jar" --dest "Location where the exe will be created" --main-jar "Name of the runnable Jar, with extention .jar at the end" --icon "Complete location where the icon of the app is .ico" --module-path "Location of jmods folder" --add-modules javafx.controls,javafx.graphics,javafx.fxml,javafx.base --win-shortcut --win-menu

    Example:

    jpackage -t exe --name "MyApp" --app-version 1.0 --input "D:\Projects\Jars\" --dest "D:\Projects\Executable" --main-jar "Guide.jar" --icon "D:\Projects\Icons\guide.ico" --module-path "D:\Projects\JavaFX\javafx-jmods-16" --add-modules javafx.controls,javafx.graphics,javafx.fxml,javafx.base --win-shortcut --win-menu

    This command has a lot more options you can add to it, so read the documentation, and also the complete list of options by running jpackage -h.