127

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.<init>(Window.java:407)
at java.awt.Frame.<init>(Frame.java:402)
at net.sourceforge.mlf.metouia.borders.MetouiaDotsBuf fer.<init>(MetouiaDotsBuffer.java:105)
at net.sourceforge.mlf.metouia.borders.MetouiaDots.<i nit>(MetouiaDots.java:66)
at net.sourceforge.mlf.metouia.borders.MetouiaToolBar Border.<init>(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.<init>(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)
2
  • i'm having the same problem, it works perfecly on console but when i use eclipse it throws the same exception i even put that code lines : Process proc_exporting =Runtime.getRuntime().exec("sudo export DISPLAY =:0.0"); still doesn't work
    – hb.Sara
    Dec 27, 2011 at 15:14
  • 3
    None of the answers give the info needed to solve this problem when connecting to a console remotely via puTTY. Any answer that addresses SSH doesn't actually explain how to make it work. Anyone know of a question that addresses this?
    – user2700923
    May 2, 2014 at 0:18

13 Answers 13

142

If you're on the main display, then

export DISPLAY=:0.0

or if you're using csh or tcsh

setenv DISPLAY :0.0

before running your app.

Actually, I'm surprised it isn't set automatically. Are you trying to start this application from a non-graphic terminal? If not, have you modified the default .profile, .login, .bashrc or .cshrc?

Note that setting the DISPLAY to :0.0 pre-supposes that you're sitting at the main display, as I said, or at least that the main display is logged on to your user id. If it's not logged on, or it's a different userid, this will fail.

If you're coming in from another machine, and you're at the main display of that machine and it's running X, then you can use "ssh -X hostname" to connect to that host, and ssh will forward the X display back. ssh will also make sure that the DISPLAY environment variable is set correctly (providing it isn't being messed with in the various dot files I mentioned above). In a "ssh -X" session, the DISPLAY environment variable will have a value like "localhost:11.0", which will point to the socket that ssh is tunnelling to your local box.

8
  • Hi, thank you very much, the first one worked for me. Yes, I am starting it from a non-graphic terminal.
    – user42155
    Mar 19, 2009 at 14:35
  • It sounds like it wants to accesss the graphics display though. Be careful not to run it when the graphics display isn't available, or it belongs to some other userid. Mar 19, 2009 at 14:36
  • 3
    note that this worked because you are/were on the console. if you were on another terminal, you would have to have an X server running on the terminal and then set the environment to point to your machine (export DISPLAY='hostname of pauls terminal':0.0 for example)
    – KevinDTimm
    Mar 19, 2009 at 15:14
  • @kevindtimm, Good point - I'm going to incorporate @Mikeage's info about ssh -X into my answer. Mar 19, 2009 at 15:17
  • 1
    In case you need to run an automated task that requires connecting to an X server you can look at xvfb, which creates a virtual X server. This is very useful for some batch tests or running tests. Dec 27, 2011 at 15:27
11

you must enable X11 forwarding in you PuTTy

to do so open PuTTy, go to Connection => SSH => Tunnels and check mark the Enable X11 forwarding

Also sudo to server and export the below variable here IP is your local machine's IP

export DISPLAY=10.75.75.75:0.0

enter image description here

1
  • It also works for connecting via MobaXTerm
    – Tunahan
    Jan 12, 2021 at 8:32
10

Are you running this from within an X11 environment? You can use a terminal window, but it has to be within X (either after a graphical login, or by running startx).

If you're already within a graphical environment, try export DISPLAY=:0 for bash like shells (bash, sh, etc) or setenv DISPLAY :0 for C shell based shells (csh, tcsh, etc)

If you've connected from another machine via SSH, you use the -X option to display the graphical interface on the machine you're sitting at (provided there's an X server running there (such as xming for windows, and your standard Linux X server).

3
  • Oh right, Slackware. Is it still as barebones as it was when I last used it 10 years ago? Mar 19, 2009 at 15:23
  • It still starts up by default in runlevel 3. Of course, if you tell it to start in runlevel 5, you'll get a pretty KDM login menu assuming you installed KDE. Mar 24, 2009 at 18:22
  • thanks! on CentOS and SSH (putty) used: export DISPLAY=:0
    – jacktrades
    Aug 21, 2012 at 15:17
5

There are many ways to do this. I did something below convenient to me and always works fine.

  1. On your remote server, make sure to install xorg-x11-xauth, xorg-x11-font-utils, xorg-x11-fonts.
  2. Run the Xming Server on you local desktop
  3. On putty, before ssh to the server, enable the X11 forwarding and set the display location to localhost:0.0
  4. On the server, .Xauthority file is generated and notice that the DISPLAY variable is already set.

    $ xauth list

    $ xauth add

To test it, type xclock or xeyes

Note: To switch user, copy the .Xauthority file to the home directory of the respective user and also export the DISPLAY variable from that user.

0
4

One more thing that might be the problem in a case similar to described - X is not forwarded and $DISPLAY is not set when 'xauth' program is not installed on the remote side. You can see it searches for it when you run "ssh -Xv ip_address", and, if not found, fails, which's not seen unless you turn on verbose mode (a fail IMO). You can usually find 'xauth' in a package with the same name.

3

Very Easy, Had this same problem then what i did was to download and install an app that would help in displaying then fixed the error.

Download this app xming:

http://sourceforge.net/project/downloading.php?

Install, then use settings on this link:

http://www.geo.mtu.edu/geoschem/docs/putty_install.html or follow this steps:

Installing/Configuring PuTTy and Xming

Once PuTTy and Xming have been downloaded to the PC, install according to their respective instructions.

Configuring Xming

Once Xming is installed, run the application called 'XLaunch' and verify that the settings are as shown:

  • select Default entries on Display Settings windows, click next
  • click next on Session Type window.
  • click next on Additional parameters window(Notice clipboard checkbox is true)
  • save configuration and click to finish.

Configuring PuTTy

After installing PuTTy, double-click on the PuTTy icon on the desktop and configure as shown:

This shows creating a login profile then saving it.

  • On ssh -> X11, click on checkbox to enable X11 forwarding.
  • on X display location textbox, type localhost:0.0

save profile then connect remotely to server to test.

Cheers!!!

1
  • Please include the essential information from the links in the answer itself, because they might go dead eventually, rendering the answer useless.
    – plamut
    Jan 28, 2016 at 10:05
3

There are two possibilities for it if your app has GUI or not:

1-) If your java app has GUI, firstly ensure that you have installed jdk package normally (non-headless). For example if you installed this:

sudo apt install openjdk-19-jre-headless

remove it:

sudo apt remove openjdk-19-jre-headless

then install the normal version:

sudo apt install openjdk-19-jre

Simply headless is using for GUIless apps. Further information you can look here: Difference between openjdk-6-jre, openjdk-6-jre-headless, openjdk-6-jre-lib

Then, either try to set DISPLAY variable as:

export DISPLAY=:0

or if it does not work (then, probably you have multiple monitors), set as:

export DISPLAY=:1

then run your jar file:

java -jar gate-5.0-beta1-build3048-installer.jar

2-) If your java app has no GUI, while you are running the app, you can try java.awt.headless=true flag as:

java -Djava.awt.headless=true -jar gate-5.0-beta1-build3048-installer.jar
1
  • removing jre-headless and installing the normal one, then exporting DISPLAY=:1 solved it for me, thanks!!
    – fredjaya
    Aug 11 at 5:24
1

For those who are trying to get an X Window application working from Windows from Linux:

What worked for me was to setup xming server on my windows machine, set X11 forwarding option in putty when I connect to the linux host and put in my windows ip address with the display port and then the display variable with my windows IP address:0.0

Dont forget to add the linux hosts IP address to the X0.hosts file to ensure that the xming server accepts traffic from that host. Took me a while to figure that out.

1
export DISPLAY=172.16.1.148:0.0

172.16.1.148 is your computer ip.

0

I have had the same issue in Ubuntu 14.04.01 when I tried to install JDK 8 and Netbeans if I launch the script inside a Byobu terminal (maybe with Screens happens the same).

Just exit Byobu and (in a graphical terminal) run the script.

0

Initial Check.

1) When you are exporting the DISPLAY to other machine, ensure you entered the command xhost + on that machine. This command allows to other machine to export their DISPLAY on this machine. There may be security constraints, just know about it. Need to check ssh -X MachineIP will not require xhost + ?

2) Some times JCONSOLE won't show all its process, since those JVM process may run with different user and you are exporting the DISPLAY with another user. so better follow CD_DIR>sudo ./jconsole

3) In WAS (WEBSPHERE); jconsole won't be able to connect its java server process, that time just go till the link, then try connecting it. This worked for me. May be this page is initializing some variables to enable jconsole to connect with that server.

WAS console > Application servers > server1 > Process definition > Java Virtual Machine


I have faced the same issue with AIX (where command line interface only available, There is no DISPLAY UI) machine. I resolved by installing

NX Client for Windows

Step 1: Through that Windows machine, I connected with unix box where GUI console is available.
Step 2: SSH to the AIX box from that UNIX box.
Step 3: set DISPLAY like "export DISPLAY=UNIXMACHINE:NXClientPORTConnectedMentionedOnTitle"
Step 4: Now if we launch any programs which requires DISPLAY; it will be launched on this UNIX box.

VNC

If you installed VNC on UNIX box where display is available; then Windows and NX Client is not required. Step 1: Use VNC to connect with Unix box where GUI console is available.
Step 2: SSH to the AIX box from that UNIX box.
Step 3: set DISPLAY like "export DISPLAY=UNIXMACHINE:VNCPORT"
Step 4: Now if we launch any programs which requires DISPLAY; it will be launched on this UNIX box.

ELSE

Step 1: SSH to the AIX box from that UNIX box.
Step 2: set DISPLAY like "export DISPLAY=UNIXMACHINE:VNCPORT"
Step 3: Now if we launch any programs which requires DISPLAY; it will be launched on this UNIX box.

0

Set the display mode is fine and also make sure that the apache Jmeter start from your USER mode, DON'T run in ROOT user.

$ cd /home/USER/apache-jmeter-5.5/
$ ./jmeter
-3

Don't forget to execute "host +" on your "home" display machine, and when you ssh to the machine you're doing "ssh -x hostname"

2
  • 14
    I would strongly recommend not to use "xhost +" since if effectively disables all security on your X server. ssh is smart enough to use xauth to setup X11 authentication automatically, so there should be no need to use xhost. Dec 27, 2011 at 15:26
  • This should be a comment, not a post. Just because you can't comment doesn't mean you should make a bad post.
    – Elliot A.
    Mar 19, 2016 at 13:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.