开发者社区> 问答> 正文

使用JavaFx运行Java Jar文件时,如何解决“图形设备初始化失败:d3d,sw”的问题

大家下午好。

尝试将Java代码作为Runnable Jar文件运行时遇到问题。我正在使用Eclipse,并且创建了一个普通的Java项目。我将JavaFX jar包含为用户库。当我使用IDE启动该程序时,它不会出现问题。要创建Jar文件,请使用Runnable Jar文件中的Java项目导出中的构建。当我检查“将所需的库提取到生成的JAR中”并运行它时,出现以下错误消息:

Error: JavaFX runtime components are missing, and are required to run this application

当我选中“将所需的库打包到生成的JAR中”并运行它时,出现以下错误消息:

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:244)
        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:835)
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:835)

有谁知道,为什么我不能运行JAR,但是在IDE中却可以正常运行?

我按照文档https://openjfx.io/openjfx-docs/的要求安装了JavaFX 。

问题来源:Stack Overflow

展开
收起
montos 2020-03-28 09:19:59 4467 0
1 条回答
写回答
取消 提交回答
  • 我找到了解决问题的方法。当我将库导出到生成的Jar时,我收到了JavaFX Runtime组件丢失的错误消息。我现在记得在Eclipse中我遇到过同样的错误,尽管代码中没有错误并且我使用了JavaFX元素。但是要启动它并运行,我必须添加VM参数。因此,当我想运行程序时,只需要在命令promt中编写此内容即可。

    假设您已经在构建Jar文件的目录中:

    java --module-path "C:\Path\to\javafx-sdk-13.0.2\lib" --add-modules javafx.controls,javafx.fxml -jar YourJar.jar
    

    现在为我工作。希望它也能帮助其他人。

    最好的祝愿

    回答来源:Stack Overflow

    2020-03-28 09:20:15
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载
The Reactive Cloud Native Arch 立即下载
JAVA开发手册1.5.0 立即下载