I have a JavaFX Gradle project which runs OK when I do an installDist
task (part of the application
Gradle plugin) in Linux (Mint 18.3).
This produces a self-contained app consisting of a Linux executable script file, a Windows .bat file, and a library full of all the .jars you need including a .jar containing your own code and resources, to run the app. These are put in a sibling directory to the "bin" directory, called "lib".
Running that executable works fine on Linux.
But then I booted up into W10 and tried to run the .bat file. I got the following errors:
Discovered throwable java.lang.RuntimeException: No toolkit found message No toolkit found
Root cause throwable java.lang.RuntimeException: No toolkit found message No toolkit found
Root cause trace:
[com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:272)
com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:267)
com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:158)
com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:658)
com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:678)
com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)]
There are a couple of aspects to my project which may complicate things
- it uses Java11 (and JavaFX11). This means that JavaFX no longer comes bundled with the rest. Both OSs are running Java 11.
- it is written in Groovy: that is, the app code, all the app code, is in Groovy, not Java.
because it is written in Groovy it was quite tricky to get the
installDist
task to work OK, even in Linux. Eventually I had to create a "launcher" class, which then calls theApplication
subclass (hereHelloFx
) and gets it to runstart
:Application.launch(HelloFx, args)
- full gory details here.
I was aware that there are slight problems in the build.gradle file when you want an executable to be runnable in these 2 different OSs, specially getting the file paths right, and the path separators, i.e. "/" for Linux, "\" for W10. But I have managed to do that previously in non-JavaFX projects, and I seem to have configured things right here.
Perhaps it might be helpful to glance inside the .bat file generated by Gradle in Linux:
...
set CLASSPATH=%APP_HOME%\lib\Organiser-1.0.7-SNAPSHOT.jar;%APP_HOME%\lib\javafx-fxml-11.0.2-linux.jar;%APP_HOME%\lib\javafx-controls-11.0.2-linux.jar;%APP_HOME%\lib\javafx-controls-11.0.2.jar;%APP_HOME%\lib\javafx-graphics-11.0.2-linux.jar;%APP_HOME%\lib\javafx-graphics-11.0.2.jar;%APP_HOME%\lib\javafx-base-11.0.2-linux.jar;%APP_HOME%\lib\javafx-base-11.0.2.jar;%APP_HOME%\lib\groovy-2.5.11.jar;%APP_HOME%\lib\logback-classic-1.2.3.jar;%APP_HOME%\lib\logback-core-1.2.3.jar;%APP_HOME%\lib\slf4j-api-1.7.25.jar
@rem Execute Organiser
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %ORGANISER_OPTS% -classpath "%CLASSPATH%" core.Launcher %CMD_LINE_ARGS%
...
From the above it certainly appears that the JavaFX files are being included on the classpath. Setting of the JavaFX module, since that is configured in build.gradle, presumably happens in the .jar file with my code... somehow?