-1

I am trying to export a runnable .jar file however I am faced with the following problems:

"VM arguments will not be part of the runnable JAR. Arguments can be passed on the command line when launching the JAR"

I ignored the warning and hit finish to create the runnable .jar file. When I double click it doesn't work.

I ran the following code in my command line:

**java -jar C:\path\file.jar --module-path "C:\pathtofxsdk11\lib"  --add-modules javafx.controls,javafx.fxml,javafx.base,javafx.swing, javafx.graphics**

After which, I received the following 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 com.sun.javafx.tk.quantum.QuantumRenderer.getInstance(QuantumRenderer.java:280)
        at com.sun.javafx.tk.quantum.QuantumToolkit.init(QuantumToolkit.java:222)
        at com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:260)
        at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:267)
        at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:158)
        at com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:658)
        at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:678)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
        at java.base/java.lang.Thread.run(Thread.java:830)
Caused by: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
        at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.init(QuantumRenderer.java:94)
        at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:124)
        ... 1 more
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:567)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:61)
Caused by: java.lang.RuntimeException: No toolkit found
        at com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:272)
        at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:267)
        at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:158)
        at com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:658)
        at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:678)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
        at java.base/java.lang.Thread.run(Thread.java:830)

I need help with creating the executable Jar.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
oshsec
  • 29
  • 4
  • The options in your command are in the wrong order: arguments placed after the name of the jar file (or main class, if you don't use the `-jar` option) are interpreted as *program* arguments, not *JVM* arguments (so they are passed to the `main(...)` method as the `args` array). I'm not 100% sure this will work but try `java --module-path "C:\pathtofxsdk11\lib" --add-modules javafx.controls,javafx.fxml,javafx.base,javafx.swing,javafx.graphics -jar C:\path\file.jar` – James_D Aug 06 '20 at 15:20
  • Also, not sure if it's a copy and paste error, but there's a space before `javafx.graphics` in your `--add-modules` option that will confuse the CLI. – James_D Aug 06 '20 at 15:22
  • 3
    Weak title. Rewrite to summarize your specific technical issue. – Basil Bourque Aug 06 '20 at 15:33
  • @James_D thank you! I adjusted my arguments and it worked from the CLI. Really appreciated. The problem I have now is making it a file where it can be double clicked for use. – oshsec Aug 06 '20 at 15:47
  • @Osh'ne As I understand it, that’s not possible because a JavaFX application relies on native libraries, not just jar files, that are not part of the standard JRE. Instead, you should create a native bundle, using [`jpackage`](https://docs.oracle.com/en/java/javase/14/docs/specs/man/jpackage.html) – James_D Aug 06 '20 at 16:17

1 Answers1

0

The options you provided in the command line are in the wrong order. Anything supplied after the name of the jar file (or the main class, if you are not using the -jar option) will be interpreted as an argument to your Java application (as opposed to an argument to the JVM), and passed to the string array in the

public static void main(String[])

method in the main class.

Thus you should use

java --module-path "C:\pathtofxsdk11\lib"  --add-modules javafx.controls,javafx.fxml,javafx.base,javafx.swing,javafx.graphics -jar C:\path\file.jar

Note that this doesn't mean the jar file can be used as an "executable jar" that can simply be run on any system, because the JavaFX runtime is not included in the standard Java runtime from version 11 onwards. Instead, you can use the jpackage tool, which is included in JDK 14, to create a native installer bundle. This bundle will include a Java runtime, which you can configure to include JavaFX.

You should first download and unzip the modular version of JavaFX (the "jmods") from here.

Then your jpackage command looks something like the following:

jpackage --module-path "C:\pathtofxmods" --add-modules javafx.controls,javafx.fxml,javafx.swing --input "C:\path" --main-jar file.jar --type exe --name MyApp --dest "C:\path\to\generated\executable"

where C:\pathtofxmods is the library you unzipped in the previous step: it should include a collection of *.jmod files. This will generate an .exe file in C:\path\to\generated\executable which will install the application on a windows system. You can distribute this - note the end users do not even need a JRE, as this will bundle a JRE with the package.

You can also run jlink independently to create the JRE (with JavaFX) that is bundled with the application. See a full tutorial and the full tool documentation.

James_D
  • 201,275
  • 16
  • 291
  • 322