2

What doesn't work

I'm trying to setup WSL2 GUI environment under the latest version Windows Insider Preview. Gedit and Thunar worked fine but when I tried to run GoLand it gave me the following error

Start Failed
Failed to initialize graphics environment

java.awt.AWTError: Can't connect to X11 window server using ':0' as the value of the DISPLAY variable.
        at java.desktop/sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
        at java.desktop/sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:102)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at java.desktop/sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:61)
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Class.java:315)
        at java.desktop/java.awt.GraphicsEnvironment$LocalGE.createGE(GraphicsEnvironment.java:101)
        at java.desktop/java.awt.GraphicsEnvironment$LocalGE.<clinit>(GraphicsEnvironment.java:83)
        at java.desktop/java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:129)
        at java.desktop/sun.awt.X11.XToolkit.<clinit>(XToolkit.java:233)
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Class.java:315)
        at java.desktop/java.awt.Toolkit$2.run(Toolkit.java:588)
        at java.desktop/java.awt.Toolkit$2.run(Toolkit.java:583)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at java.desktop/java.awt.Toolkit.getDefaultToolkit(Toolkit.java:582)
        at java.desktop/java.awt.Toolkit.getEventQueue(Toolkit.java:1499)
        at java.desktop/java.awt.EventQueue.invokeLater(EventQueue.java:1318)
        at com.intellij.idea.StartupUtil.lambda$scheduleInitUi$9(StartupUtil.java:347)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:668)
        at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:665)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:665)
        at java.base/java.lang.Thread.run(Thread.java:829)

-----
Your JRE: 11.0.11+9-b1341.57 amd64 (JetBrains s.r.o.)
/home/ubuntu/executables/GoLand-2021.1.3/jbr

I'm using WSL2 - Ubuntu-20.04, Windows 11 build 22000.100

What works

  1. start VcXSrv in Windows
  2. $DISPLAY is set to $WINDOWS_IPADDR:0, startxfce4 in wsl2
  3. start GoLand in VcXSrv window
  4. Everything works fine

p.s. I defined a environment variable WINDOWS_IPADDR=$(cat /etc/resolv.conf | grep nameserver | cut -d ' ' -f 2).

What I have tried

  1. I've tried Pycharm and Idea and both of them displayed the same error.
  2. export DISPLAY=localhost:0 && goland.sh gives the same error.
  3. export DISPLAY=0:0 && goland.sh gives the same error.
  4. export DISPLAY=$WINDOWS_IPADDR:0 && goland.sh will not show this error, but nothing happened.
  5. I tried to install a new openjdk-11 which might be different from openjdk-11-jdk-headless but it didn't change the JRE path used by IntelliJ-idea/GoLand/PyCharm, which is always IDE_INSTALL_PATH/jbr, e.g. goland alwayws use jre in /home/ubuntu/executables/GoLand-2021.1.3/jbr

I'm not familiar with X11 or X-Server so I tried searching for similar issues but few is related. I'm think it might be some kind of compatibility issue with WSLg. Does anyone know how to fix this error? Any and all help/direction is appreciated.

UPDATE:

I install a new distro and everything just magically work now. However, I mistakenly deleted the original distro so I cannot test it anymore. I guess WSLg cannot work very well with gnome & xfce4 as I've installed both desktop environments in WSL. Think twice before you want to install multiple desktops!

ImPiNoron
  • 71
  • 1
  • 5
  • Did you find this: https://stackoverflow.com/questions/10165761/java-cant-connect-to-x11-window-server-using-localhost10-0-as-the-value-of-t – MegaIng Jul 25 '21 at 17:17
  • Why do you need to run the IDE inside WSL? You can just run/debug your project (inside WSL) via SDK located inside WSL. See https://www.jetbrains.com/help/go/how-to-use-wsl-development-environment-in-product.html – Konstantin Annikov Jul 26 '21 at 02:33
  • @MegaIng Thank your for this post. I've tried most of the solutions introduced in it but none of them work for me. – ImPiNoron Jul 26 '21 at 03:07
  • @KonstantinAnnikov I need to use the build result (a .so file) of **build configuration A** from **build configuration B**. GoLand doesn't support specifying output path for remote targets, which means GoLand will save the build result to a randomly generated temp path and the path changes everytime I run the build configuration, so I have to use GoLand in WSL to fix problem. – ImPiNoron Jul 26 '21 at 03:15

0 Answers0