javajavafxwindows-subsystem-for-linux

InternalError running JavaFX 15 application on Windows Subsystem for Linux


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

UPDATE Testing WSL on new Windows 11 machine with JDK22 and JavaFX 22: the fix is the same as below, but there is a different error message given for missing GTK install:

java.lang.UnsatisfiedLinkError: /mnt/c/linux/jdk-22/lib/libawt_xawt.so: libXrender.so.1: cannot open shared object file: No such file or directory

Solution

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

    sudo apt install libgtk-3-0