0

I just switched from Ubuntu 20.04 distro back to Windows with integrated WSL 2, and I am having trouble running my JavaFX project.

I get the following error stacktrace around launch(args) inside main method :

hexaquarks@LAPTOP-KPPA3O52:~/Particle_Geometry_Simulation$  cd /home/hexaquarks/Particle_Geometry_Simulation ; /usr/bin/env /usr/lib/jvm/java-11-openjdk-amd64/bin/java --module-path /usr/share/openjfx/lib --add-modules javafx.controls,javafx.fxml,javafx.swing -Dfile.encoding=UTF-8 @/tmp/cp_eiv0idm2cbh7kd2tl4ddw7ff7.argfile AppFrame 
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:566)
        at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.UnsupportedOperationException: Unable to open DISPLAY
        at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$new$6(GtkApplication.java:173)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        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:258)
        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

System Configurations

$ java -version
openjdk version "11.0.11" 2021-04-20                                                                                    OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.20.04)  
OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.20.04, mixed mode, sharing)   

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal 
DISTRIB_DESCRIPTION="Ubuntu 20.04.3 LTS" 

$ java -version
openjdk version "11.0.11" 2021-04-20 
OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.20.04) 
OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.20.04, mixed mode, sharing) 

Project Tree

$ [.../Particle_Geometry_Simulator] tree
.
├── .vscode
|   ├── launch.json
|   └── settings.json
├── bin
└── src
    ├── AppFrame.java
    ├── ... // f files here
    └── ParticleFunJavaFx.fxml

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "java",
            "name": "Launch AppFrame",
            "request": "launch",
            "vmArgs": "--module-path /usr/share/openjfx/lib --add-modules javafx.controls,javafx.fxml,javafx.swing",
            "mainClass": "AppFrame",
            "projectName": "Particle_Geometry_Simulation_4f401646"
        },
        {
            "type": "java",
            "name": "Launch Current File",
            "request": "launch",
            "mainClass": "${file}"
        },
        {
            "type": "java",
            "name": "Launch GameFrame",
            "request": "launch",
            "vmArgs": "--module-path /usr/share/openjfx/lib --add-modules javafx.controls,javafx.fxml,javafx.swing",
            "mainClass": "GameFrame",
            "projectName": "Particle_Geometry_Simulation_4f401646"
        }
    ]
}

settings.json

{
    "java.project.sourcePaths": ["src"],
    "java.project.outputPath": "bin",
    "java.project.referencedLibraries": [
        "lib/**/*.jar",
        "/usr/share/openjfx/lib/javafx-swt.jar",
        "/usr/share/openjfx/lib/javafx.media.jar",
        "/usr/share/openjfx/lib/javafx.web.jar",
        "/usr/share/openjfx/lib/javafx.graphics.jar",
        "/usr/share/openjfx/lib/javafx.fxml.jar",
        "/usr/share/openjfx/lib/javafx.controls.jar",
        "/usr/share/openjfx/lib/javafx.base.jar",
        "/usr/share/openjfx/lib/javafx.swing.jar"
    ]
}

Things I have tried

I looked at almost every post on SO regarding this issue with no success.

sudo apt install libgtk-3-0

was not a fix since I had already this installed.

I also tried to delete openjfx and reinstall it from a different mirror, with no success. Currently the package I have, I have installed it with

sudo apt install openjfx

Does anyone have an idea of what may be going on here ?

hexaquark
  • 883
  • 4
  • 16
  • 2
    Are you running a Windows Insider build with GUI (WSLg) support? If not, this would be expected behavior unless you have installed a third-party X server or are using `xrdp`. See [this question](https://stackoverflow.com/questions/61860208/wsl-2-run-graphical-linux-desktop-applications-from-windows-10-bash-shell-erro) and it's multiple possible answers. If you are running a system with WSL GUI support, please edit your question to include the mechanism you are using. Thanks! – NotTheDr01ds Sep 14 '21 at 04:52
  • 1
    Based on your self-answer below, this was definitely a duplicate of the question/answers I linked above. I'd recommend accepting the "Duplicate" suggestion you should see in the header. – NotTheDr01ds Sep 14 '21 at 23:04
  • 1
    @NotTheDr01ds Incorrect, while I thank you for suggesting a duplicate, I followed every instruction in all the comments, but all of them were insufficient in fixing the problem. You have clearly not read all the answers provided on there and compared with the link I have provided, otherwise, you wouldn't downvote my answer. I am only trying to be helpful to someone in the future. – hexaquark Sep 15 '21 at 00:13

1 Answers1

0

Answe was found

My WSL 2 out-of-the-box was unable to run graphical applications.

For instance running

$ xclock

in the shell returned an error since DISPLAY variable is not set and X11 was not installed, nor allowed across firewall.

Following step by step this guide fixed my problem

hexaquark
  • 883
  • 4
  • 16