本文介绍了如何解决"d3d,sw的图形设备初始化失败"?使用JavaFx运行Java Jar文件时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家下午好.

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

I'm having a problem when I try to run my Java Code as a Runnable Jar file. I'm using Eclipse and I created a normal Java Project. I included the JavaFX jars as a User Libary. The Program runs without a problem when I start it with the IDE. To create the Jar file I use the the build in Export of a Java Project in the Runnable Jar file.When I check "Extract required libaries into generated JAR" and run it, I get this Error Message:

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

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

When I check "Package required libaries into generated JAR" and run it, I get this Error Message:

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中却可以正常运行吗?

Does anyone know, why I cannot run the JAR but in the IDE it runs normally?

我按照此处的文档 https://openjfx.io/openjfx-docs/.

推荐答案

我找到了解决我的问题的方法.当我将库导出到生成的Jar中时,我收到了JavaFX Runtime组件丢失的错误消息.我现在记得在Eclipse中我遇到过同样的错误,尽管代码中没有错误并且我使用了JavaFX元素.但是要启动它并运行,我必须添加VM参数.因此,当我要运行程序时,只需在命令promt中编写此代码即可.

I found a solution to my Problem. When I Export the Libaries into the Generated Jar I got the Error that the JavaFX Runtime components are missing. I now remembered that I got the same Error in Eclipse before although there was no Error in the Code and I used JavaFX elements. But to get it up and running I had to add VM Arguments. So I only had to write this in the command promt when I wanted to run the program.

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

Assuming you already are in the directory of your build Jar file:

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

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

It's working now for me. Hope it will help others too.

最良好的祝愿

这篇关于如何解决"d3d,sw的图形设备初始化失败"?使用JavaFx运行Java Jar文件时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!