发生在 Windows Subsystem for Linux 上运行 JavaFX 15 应用程序时的内部错误。

huangapple go评论80阅读模式
英文:

InternalError running JavaFX 15 application on Windows Subsystem for Linux

问题

我在尝试在Windows Subsystem for Linux WSL2 / Ubuntu 20.04上运行JavaFX 15应用程序时遇到了问题,并需要关于接下来尝试的建议。

到目前为止,我已经成功地在WSL内运行了所有我通常在Windows/JDK15上进行的Java构建,包括那些具有Swing / AWT依赖关系的构建。AWT / Swing测试应用在WSL内成功运行,并引用JDK15,并在Windows 10上运行X Windows。然而,我无法使任何JavaFX应用程序运行,甚至是HelloFX示例:

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

public class HelloFX extends Application {
    public void start(Stage stage) {
        String javaVersion = System.getProperty("java.version");
        String javafxVersion = System.getProperty("javafx.version");
        Label l = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + ".");
        Scene scene = new Scene(new StackPane(l), 640, 480);
        stage.setScene(scene);
        stage.show();
    }
    public static void main(String[] args) {
        launch();
    }
}

我尝试过在Windows上使用各种X服务器 - X/Cygwin、X410、VcXsrv和XMing。在使用VcXsrv运行HelloFX时,出现以下错误消息:

> echo $PATH_TO_FX
/mnt/c/linux/javafx-sdk-15/lib
> $JAVA_HOME/bin/java -version
openjdk version "15" 2020-09-15
OpenJDK Runtime Environment (build 15+36-1562)
OpenJDK 64-Bit Server VM (build 15+36-1562, mixed mode, sharing)

> $JAVA_HOME/bin/java --module-path $PATH_TO_FX --add-modules javafx.controls -cp build/classes HelloFX

libGL error: No matching fbConfigs or visuals found
libGL error: failed to load driver: swrast
Prism-ES2 Error : GL_VERSION (major.minor) = 1.4
Exception in thread "main" java.lang.reflect.InvocationTargetException
    ...
Caused by: java.lang.UnsupportedOperationException: Internal Error
    ...

一些其他网站,如如何在WSL2上设置工作的X11转发,提到了使用export LIBGL_ALWAYS_INDIRECT=1。使用此设置,不会打印出2个libGL error消息,但我仍然得到相同的错误堆栈。

从相同的bash中以相同的DISPLAY运行的swing/AWT Java应用程序可以正常运行,没有错误。我使用的是OpenJDK15 LinuxGluon JavaFX 15。我还尝试过使用jlink创建带有JDK15和JavaFX模块的JRE - 但仍然出现相同的错误消息。

正如建议的,当使用-Djdk.gtk.verbose=true运行时,会出现以下消息:

checking GTK version 3
trying GTK library libgtk-3.so.0
trying GTK library libgtk-3.so
trying GTK library libgtk-x11-2.0.so.0
trying GTK library libgtk-x11-2.0.so
英文:

I am stuck when trying to run JavaFX 15 applications on Windows Subsystem for Linux WSL2 / Ubuntu 20.04, and need suggestions on the next steps to try.

So far I have been able to run all my Java builds I normally do on Windows/JDK15 inside WSL including those with Swing / AWT dependencies. The AWT / Swing test applications run successfully within WSL and reference JDK15, and running X Windows on Windows 10. However I cannot get any JavaFX application to run, even the HelloFX sample:

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

public class HelloFX extends Application {
    public void start(Stage stage) {
        String javaVersion = System.getProperty("java.version");
        String javafxVersion = System.getProperty("javafx.version");
        Label l = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + ".");
        Scene scene = new Scene(new StackPane(l), 640, 480);
        stage.setScene(scene);
        stage.show();
    }
    public static void main(String[] args) {
        launch();
    }
}

I've tried various X servers on Windows - X/Cygwin, X410, VcXsrv and XMing. Here is error message when running HelloFX with VcXsrv:

> echo $PATH_TO_FX
/mnt/c/linux/javafx-sdk-15/lib
> $JAVA_HOME/bin/java -version
openjdk version "15" 2020-09-15
OpenJDK Runtime Environment (build 15+36-1562)
OpenJDK 64-Bit Server VM (build 15+36-1562, mixed mode, sharing)

> $JAVA_HOME/bin/java --module-path $PATH_TO_FX --add-modules javafx.controls -cp build/classes HelloFX

libGL error: No matching fbConfigs or visuals found
libGL error: failed to load driver: swrast
Prism-ES2 Error : GL_VERSION (major.minor) = 1.4
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:64)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1071)
Caused by: java.lang.UnsupportedOperationException: Internal Error
    at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$new$6(GtkApplication.java:189)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:312)
    at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.<init>(GtkApplication.java:171)
    at javafx.graphics/com.sun.glass.ui.gtk.GtkPlatformFactory.createApplication(GtkPlatformFactory.java:41)
    at javafx.graphics/com.sun.glass.ui.Application.run(Application.java:144)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:280)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:269)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:158)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:658)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:409)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
    ... 5 more

Some other sites such as How to set up working X11 forwarding on WSL2
mention the use of export LIBGL_ALWAYS_INDIRECT=1. With this setting, the 2 libGL error messages aren't printed but I get the same error stack.

A swing/AWT java app run from the same bash with the same DISPLAY runs fine with no errors. I am using the OpenJDK15 Linux and Gluon JavaFX 15. I've also tried jlink to make JRE with JDK15 and JavaFX modules - the same error message.

As suggested, when running with -Djdk.gtk.verbose=true the following messages appear:

checking GTK version 3
trying GTK library libgtk-3.so.0
trying GTK library libgtk-3.so
trying GTK library libgtk-x11-2.0.so.0
trying GTK library libgtk-x11-2.0.so

答案1

得分: 5

感谢@José Pereda和@mipa的评论,帮助我朝着修复的方向前进,添加了libgtk-3

sudo apt安装libgtk-3-0
英文:

Thanks for the comments @José Pereda and @mipa which helped me towards a fix, adding libgtk-3

sudo apt install libgtk-3-0

huangapple
  • 本文由 发表于 2020年10月8日 21:08:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/64263232.html
匿名

发表评论

匿名网友

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

确定