“Graphics Device initialization failed” 在运行 jpackage 后运行 JavaFX 应用程序时出现?

huangapple 未分类评论43阅读模式
英文:

"Graphics Device initialization failed" when running JavaFX application after running jpackage?

问题

由于篇幅较长,我将为您提供分段翻译:

正如您可能从标题中猜到的那样,我正在尝试为我的JavaFX应用程序生成可部署的版本。我已经能够通过maven编译成JAR并通过指定路径到javafx.controls来运行它。然而,当我在使用Jpackage将JAR打包后运行应用程序(再次指定javafx的路径),我会得到一个致命的RuntimeException(完整的堆栈跟踪如下)。

这是我一直在尝试在使用完整代码之前使Jpackage工作的代码(此文件为src/main/java/sample/Main.java):

// 代码部分省略

我正在使用以下pom.xml文件(位于项目根目录):

<!-- 代码部分省略 -->

我一直在使用mvn clean package将应用程序构建成JAR。

如果我运行创建的JAR,应用程序就可以正常运行(我没有计划分发JAR,所以不需要指定JavaFX的路径):

$ java --module-path $PATH_TO_FX --add-modules javafx.controls -jar HelloWorld-1.0-SNAPSHOT.jar

现在,当我在这个JAR上运行jpackage(专门用于Linux app-image)时:

$ jpackage --type app-image -n HelloWorld -i . --main-class sample.Main --main-jar HelloWorld-1.0-SNAPSHOT.jar --module-path $PATH_TO_FX --add-modules javafx.controls
WARNING: Using incubator modules: jdk.incubator.jpackage
$ chmod +x Hello/bin/Hello

运行生成的应用图像(./HelloWorld/bin/HelloWorld)会产生此错误:

Graphics Device initialization failed for : es2, sw
Error initializing QuantumRenderer: no suitable pipeline found
java.lang.RuntimeException: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
// 错误部分省略

如果有所帮助,我目前正在运行Linux Mint 19,使用Java 14.0.2(从Adopt OpenJDK下载)和JavaFX 11.0.2。

我在其他地方也找到了这个错误,但没有任何解决方案起作用(大多数情况下,它们根本无法运行代码)。

我完全被困住了,不知道从哪里开始,因此非常感谢任何帮助。

英文:

As you probably guessed from the title, I'm trying to produce a deployable version for my JavaFX application. I've been able to compile to a JAR (through maven) and run it by specifying the path to javafx.controls. However, when I run the app after packaging the JAR with Jpackage (again specifying the path to javafx) I get a fatal RuntimeException (full stack trace below).

This is the code I've been using to try and get Jpackage working before using it on my full code (this file is src/main/java/sample/Main.java):

package sample;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

public class Main extends Application {
	public static void main(String[] args) {
		launch(args);
	}

	@Override
	public void start(Stage primaryStage) throws Exception {
		BorderPane root = new BorderPane();
		root.setCenter(new Label(&quot;Hello, World!&quot;));
		primaryStage.setTitle(&quot;Hello World&quot;);
		primaryStage.setScene(new Scene(root, 300, 275));
		primaryStage.show();
	}
}

And I'm using this pom.xml (in the project root):

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
		 xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
		 xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
	&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;

	&lt;groupId&gt;Hello&lt;/groupId&gt;
	&lt;artifactId&gt;HelloWorld&lt;/artifactId&gt;
	&lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;

	&lt;build&gt;
		&lt;plugins&gt;
			&lt;plugin&gt;
				&lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt;
				&lt;configuration&gt;
					&lt;archive&gt;
						&lt;manifest&gt;
							&lt;addClasspath&gt;true&lt;/addClasspath&gt;
							&lt;mainClass&gt;sample.Main&lt;/mainClass&gt;
						&lt;/manifest&gt;
					&lt;/archive&gt;
					&lt;descriptorRefs&gt;
						&lt;descriptorRef&gt;jar-with-dependencies&lt;/descriptorRef&gt;
					&lt;/descriptorRefs&gt;
					&lt;appendAssemblyId&gt;false&lt;/appendAssemblyId&gt;
				&lt;/configuration&gt;
				&lt;executions&gt;
					&lt;execution&gt;
						&lt;id&gt;make-my-jar-with-dependencies&lt;/id&gt;
						&lt;phase&gt;package&lt;/phase&gt;
						&lt;goals&gt;
							&lt;goal&gt;single&lt;/goal&gt;
						&lt;/goals&gt;
					&lt;/execution&gt;
				&lt;/executions&gt;
			&lt;/plugin&gt;
		&lt;/plugins&gt;
	&lt;/build&gt;

	&lt;dependencies&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.openjfx&lt;/groupId&gt;
			&lt;artifactId&gt;javafx-controls&lt;/artifactId&gt;
			&lt;version&gt;11.0.2&lt;/version&gt;
		&lt;/dependency&gt;
	&lt;/dependencies&gt;

	&lt;properties&gt;
		&lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
		&lt;maven.compiler.source&gt;14&lt;/maven.compiler.source&gt;
		&lt;maven.compiler.target&gt;14&lt;/maven.compiler.target&gt;
	&lt;/properties&gt;
&lt;/project&gt;

I've been building the application into a JAR using mvn clean package.

The application runs fine if I run the created JAR (I'm not planning on distributing the JAR so having to specify a path to JavaFX isn't really an issue):

$ java --module-path $PATH_TO_FX --add-modules javafx.controls -jar HelloWorld-1.0-SNAPSHOT.jar

Now when I run jpackage on this JAR (specifically for a Linux app-image):

$ jpackage --type app-image -n HelloWorld -i . --main-class sample.Main --main-jar HelloWorld-1.0-SNAPSHOT.jar --module-path $PATH_TO_FX --add-modules javafx.controls
WARNING: Using incubator modules: jdk.incubator.jpackage
$ chmod +x Hello/bin/Hello

Running the produced app image (./HelloWorld/bin/HelloWorld) produces this error:

Graphics Device initialization failed for :  es2, sw
Error initializing QuantumRenderer: no suitable pipeline found
java.lang.RuntimeException: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer.getInstance(Unknown Source)
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.init(Unknown Source)
        at javafx.graphics/com.sun.javafx.tk.Toolkit.getToolkit(Unknown Source)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(Unknown Source)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(Unknown Source)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.startToolkit(Unknown Source)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)
        at java.base/sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.init(Unknown Source)
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(Unknown Source)
        at java.base/java.lang.Thread.run(Unknown Source)
Exception in thread &quot;main&quot; java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)
        at java.base/sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: No toolkit found
        at javafx.graphics/com.sun.javafx.tk.Toolkit.getToolkit(Unknown Source)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(Unknown Source)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(Unknown Source)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.startToolkit(Unknown Source)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source)
        ... 5 more
HelloWorld Failed to launch JVM

The same error occurs if I create and install a deb file.

If it helps, I'm currently running Linux Mint 19, with Java 14.0.2 (downloaded from Adopt OpenJDK) and JavaFX 11.0.2.

I've found a few other places online with this error, but none of the solutions have worked (and mostly they have been unable to run the code at all).

I'm completely stuck and don't know where to go from here, so any help is really appreciated.

huangapple
  • 本文由 发表于 2020年7月24日 23:28:23
  • 转载请务必保留本文链接:https://java.coder-hub.com/63076702.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定