No x11 display variable was set linux

Encountered with «java.awt.HeadlessException: No X11 DISPLAY variable was set, but this program performed an operation which requires it.» [closed]

For anyone who may encounter the same problem in the future, it turns out that the problem is because of WSL2. It needs some additional settings to run graphical programs. virtualizationreview.com/articles/2017/02/08/…

@QiuyuLi The fact you’re executing this in WSL2 is very important information that should have been included in your question.

1 Answer 1

I’m presuming you are running Linux or at the very least some form of Unix. That error states there is no X11 display. Either the system is ‘head-less’ meaning no GUI or perhaps even monitor OR you don’t have X11 setup properly.

Now if you don’t mean to use a GUI on this system then something in your java code is making a call to a SWING component. SWING is built on the older AWT which is why you are seeing both in the stack trace above.

Presuming you have the source code, step through the debugger to find the offending line of code and remove it. OR you need to setup a GUI on your Linux system.

Linked

Hot Network Questions

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.14.43533

Читайте также:  Install all perl modules linux

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

Getting a HeadlessException: No X11 DISPLAY variable was set

You have to set the DISPLAY environment variable to the address of your X11 server, e.g. DISPLAY=localhost:0.0 , before starting your Java application.

I have the same issue, and my DISPLAY variable is correctly set and exported — I can start up an ‘xterm’ with no issue for instance. Must be something else going on here as well.

Great answer @Raphael B to a terribly vague question. Sorted my issue on the Raspberry Pi which wasn’t setting DISPLAY when startx was called.

6 Answers 6

I assume you’re trying to tunnel into some unix box.

Make sure X11 forwarding is enabled in your PuTTY settings.

enter image description here

This appears to be a more general SWING/AWT/JDK problem that just the JBOSS installer:

The accepted answer below solved the issue for me :

(«sudo apt-get install openjdk-6-jdk»)

Your system does not have a GUI manager. Happens mostly in Solaris/Linux boxes. If you are using GUI in them make sure that you have a GUI manager installed and you may also want to google through the DISPLAY variable.

«GUI Manager» is not the word you’re after. It’s an X11 Server. And barely having it installed is not enough. You’d need it running and you need to have DISPLAY set accordingly.

I think you are trying to run some utility or shell script from UNIX\LINUX which has some GUI. Anyways

SOLUTION: dude all you need is an XServer & X11 forwarding enabled. I use XMing (XServer). You are already enabling X11 forwarding. Just Install it(XMing) and keep it running when you create the session with PuTTY.

Читайте также:  Permission denied to open file in linux

Problem statement – Getting java.awt.HeadlessException while trying to initialize java.awt.Component from the application as the tomcat environment does not have any head(terminal).

Issue – The linux virtual environment was setup without a virtual display terminal. Tried to install virtual display – Xvfb, but Xvfb has been taken off by the redhat community.

Solution – Installed ‘xorg-x11-drv-vmware.x86_64’ using yum install xorg-x11-drv-vmware.x86_64 and executed startx. Finally set the display to :0.0 using export DISPLAY=:0.0 and then executed xhost +

In my case it was not a problem with the display server or a window manager on my Arch Linux. Other GUI apps launched without a hitch from terminal. After a little digging I decided to print out all the system properties ( System.getProperties() ) and realized that the JVM ( java executable) I was using was not from the JDK downloaded from Oracle’s website but from the one supplied by my system’s package manager.

Apparently, my system had headless version of openjdk installed. The JVM supplied by this openjdk package had no support for display and peripheral devices, hence headless. That’s why I was getting the HeadlessException.

Some folks suggest to install the regular version of openjdk where JVM runs in non-headless mode unless instructed to do otherwise. Other solution is to always use JVM from the JDK you downloaded from Oracle. I chose the latter.

I setup an alias in my bash to java keyword.

alias java="/path/to/downloaded/jdk/bin/java " 

I then tested the graphics capabilities of both JVMs with this code:

import java.awt.GraphicsEnvironment; // Inside main method: System.out.println(GraphicsEnvironment.isHeadless()); 

The above code printed true when executed with system’s JVM and printed false when executed with downloaded JVM. My actual code using Swing ran fine too.

Читайте также:  Build linux driver module

Источник

«No X11 DISPLAY variable» — what does it mean?

I am trying to install a Java application on my Linux machine (Slackware). I have received the following error, and I do not understand it. Could you advise me how to approach the problem? Thank you. Here is what I get: (I see that some X11 DISPLAY variable needs to be set, but what value should I give it and how?)

~$ java -jar gate-5.0-beta1-build3048-installer.jar - ERROR - java.awt.HeadlessException: No X11 DISPLAY variable was set, but this program performed an operation which requires it. java.awt.HeadlessException: No X11 DISPLAY variable was set, but this program performed an operation which requires it. at java.awt.GraphicsEnvironment.checkHeadless(Graphic sEnvironment.java:159) at java.awt.Window.(Window.java:407) at java.awt.Frame.(Frame.java:402) at net.sourceforge.mlf.metouia.borders.MetouiaDotsBuf fer.(MetouiaDotsBuffer.java:105) at net.sourceforge.mlf.metouia.borders.MetouiaDots.(MetouiaDots.java:66) at net.sourceforge.mlf.metouia.borders.MetouiaToolBar Border.(MetouiaToolBarBorder.java:49) at net.sourceforge.mlf.metouia.MetouiaLookAndFeel.ini tComponentDefaults(MetouiaLookAndFeel.java:241) at javax.swing.plaf.basic.BasicLookAndFeel.getDefault s(BasicLookAndFeel.java:130) at javax.swing.plaf.metal.MetalLookAndFeel.getDefault s(MetalLookAndFeel.java:1591) at javax.swing.UIManager.setLookAndFeel(UIManager.jav a:537) at javax.swing.UIManager.setLookAndFeel(UIManager.jav a:581) at com.izforge.izpack.installer.GUIInstaller.loadLook AndFeel(GUIInstaller.java:373) at com.izforge.izpack.installer.GUIInstaller.(G UIInstaller.java:116) at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Construc tor.java:513) at java.lang.Class.newInstance0(Class.java:355) at java.lang.Class.newInstance(Class.java:30 at com.izforge.izpack.installer.Installer.main(Instal ler.java:62) 

Источник

Оцените статью
Adblock
detector