Reputation: 15652
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
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 the Application
subclass (here HelloFx
) and gets it to run start
:
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?
Upvotes: 0
Views: 361
Reputation: 347
From the documentation available at https://docs.oracle.com/javafx/2/deployment/self-contained-packaging.htm
in section 6.2 it states
Package per target platform Self-contained application packages are platform specific and can only be produced for the same system that you build on. If you want to deliver self-contained application packages on Windows, Linux and Mac you will have to build your project on all three platforms.
As you can see from your .bat excerpt, the JavaFX modules are platform specific, indicating 'linux'
I have never personally leveraged gradle to build multiple platforms but I believe there are some answers on here who have, check this one I quickly found https://stackoverflow.com/a/53760018/3625077
Short of building in Windows native or via VM, you can possibly open a new question and post your build.gradle file and the community could help you sort this out
Upvotes: 1