My question is kind of a two parter:
CAN I even include the JavaFX modules in a JPackaged app such that a user doesn't have to go and install a specific version of JavaFX libraries before installing my app?
If #1 is possible, how do I do that and/or what am I doing wrong when I attempt it?
My application was originally Java 8, and I upgraded it to Java 17. Currently:
- Windows 10
- Java 17.0.6 LTS
- JavaFX 19.0.2.1
My app is non-modular and being built with maven and packaged into a monolithic jar with all dependencies (except JavaFX modules) using the Maven Assembly Plugin:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.github.iguanastin.app.MyAppKt</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
I'm currently using jpackage to package my app into an installable EXE for Windows:
& jpackage.exe
--input ./input
--dest ./output
-n MyApp
--app-version 1.0.0
--java-options "--module-path 'C:\Program Files\Java\javafx-sdk-21\lib' --add-modules javafx.controls --add-opens=javafx.graphics/javafx.scene=ALL-UNNAMED"
--main-jar ./myapp-jar-with-dependencies.jar
Which works fine, as long as the user has manually installed JavaFX in: C:\Program Files\Java\javafx-sdk-21
.
As I understand it this isn't the way it SHOULD be packaged, because the --module-path
and --add-modules
should be passed to Jpackage and not as JVM arguments with the --java-options
argument. However, when I try to package it like so:
& jpackage.exe
--input ./input
--dest ./output
-n MyApp
--app-version 1.0.0
--module-path 'C:\Program Files\Java\javafx-sdk-21\lib'
--add-modules javafx.controls
--java-options '--add-opens=javafx.graphics/javafx.scene=ALL-UNNAMED'
--main-jar ./myapp-jar-with-dependencies.jar
It creates an EXE with no errors and installs normally, but when I try to run it I get this error:
Graphics Device initialization failed for : d3d, sw
Error initializing QuantumRenderer: no suitable pipeline found
java.lang.RuntimeException: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
at javafx.graphics@21-ea/com.sun.javafx.tk.quantum.QuantumRenderer.getInstance(Unknown Source) at javafx.graphics@21-ea/com.sun.javafx.tk.quantum.QuantumToolkit.init(Unknown Source)
at javafx.graphics@21-ea/com.sun.javafx.tk.Toolkit.getToolkit(Unknown Source)
at javafx.graphics@21-ea/com.sun.javafx.application.PlatformImpl.startup(Unknown Source)
at javafx.graphics@21-ea/com.sun.javafx.application.PlatformImpl.startup(Unknown Source)
at javafx.graphics@21-ea/com.sun.javafx.application.LauncherImpl.startToolkit(Unknown Source)
at javafx.graphics@21-ea/com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
at javafx.graphics@21-ea/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
at javafx.graphics@21-ea/com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.init(Unknown Source)
at javafx.graphics@21-ea/com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(Unknown Source)
... 1 more
Exception in thread "main" java.lang.RuntimeException: No toolkit found
at javafx.graphics@21-ea/com.sun.javafx.tk.Toolkit.getToolkit(Unknown Source)
at javafx.graphics@21-ea/com.sun.javafx.application.PlatformImpl.startup(Unknown Source)
at javafx.graphics@21-ea/com.sun.javafx.application.PlatformImpl.startup(Unknown Source)
at javafx.graphics@21-ea/com.sun.javafx.application.LauncherImpl.startToolkit(Unknown Source)
at javafx.graphics@21-ea/com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
at javafx.graphics@21-ea/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Failed to launch JVM
Which appears to be caused by missing/unlinked JavaFX dlls according to this post. I also found this Github issue which suggests using the JavaFX jmods instead of the SDK, but the result is the same. I forget where, but another post I found suggested adding the sdk /bin
folder to the app folder, which also gives the same error at runtime.
After spending hours trying out different combinations of the above solutions with jmods, sdk, etc. I'm still not getting anywhere on this problem.
CodePudding user response:
I'm answering my own question because I found the solution. Yes, you can include JavaFX in a jpackage launcher, and my problem was that I had accidentally downloaded the JavaFX jmods for aarch64 linux instead of windows.