【发布时间】:2020-11-26 20:38:55
【问题描述】:
我正在尝试导出一个可运行的 .jar 文件,但是我遇到了以下问题:
“VM 参数不会成为可运行 JAR 的一部分。启动 JAR 时可以在命令行上传递参数”
我忽略了警告并点击完成以创建可运行的 .jar 文件。当我双击它不起作用。
我在命令行中运行了以下代码:
**java -jar C:\path\file.jar --module-path "C:\pathtofxsdk11\lib" --add-modules javafx.controls,javafx.fxml,javafx.base,javafx.swing, javafx.graphics**
之后,我收到以下错误:
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)
我在创建可执行 Jar 方面需要帮助。
【问题讨论】:
-
命令中的选项顺序错误:放在 jar 文件(或主类,如果您不使用
-jar选项)名称之后的参数被解释为 program 参数,而不是 JVM 参数(因此它们作为args数组传递给main(...)方法)。我不是 100% 确定这会起作用,但请尝试java --module-path "C:\pathtofxsdk11\lib" --add-modules javafx.controls,javafx.fxml,javafx.base,javafx.swing,javafx.graphics -jar C:\path\file.jar -
另外,不确定这是否是复制和粘贴错误,但在您的
--add-modules选项中javafx.graphics之前有一个空格会混淆CLI。 -
弱标题。重写以总结您的具体技术问题。
-
@James_D 谢谢!我调整了我的论点,它在 CLI 中起作用。非常感谢。我现在遇到的问题是把它变成一个可以双击使用的文件。
-
@Osh'ne 据我了解,这是不可能的,因为 JavaFX 应用程序依赖于本机库,而不仅仅是 jar 文件,它们不是标准 JRE 的一部分。相反,您应该使用
jpackage创建一个原生包
标签: java eclipse javafx jar java-13