wood burning stoves
The moose likes Linux / UNIX and the fly likes Display variable on unix Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Display variable on unix" Watch "Display variable on unix" New topic

Display variable on unix

pramod karnani
Ranch Hand

Joined: May 22, 2007
Posts: 88

When I tried to run runme.jar file on unix , I am getting this exception

Exception in thread "main" java.awt.HeadlessException:
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:159)
at java.awt.Window.<init>(Window.java:414)
at java.awt.Frame.<init>(Frame.java:403)
at javax.swing.JFrame.<init>(JFrame.java:207)
at suncertify.gui.MainWindow.<init>(MainWindow.java:110)
at suncertify.gui.ApplicationRunner.<init>(ApplicationRunner.java:75)
at suncertify.gui.ApplicationRunner.main(ApplicationRunner.java:49)

How to solve this , how to set display variable X11 DISPLAY on unix?

Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11776

I'm going to move this to the Unix / Linux forum, since this is only tangentially related to the SCJD assignment.

Are you working on the physical Unix machine? That is, can you confirm that you are not telnetting in, or otherwise connecting remotely?

Are you running a graphical user interface on the Unix system? Under Unix this should be the X11 Window System (often called X11 or X). Many Unix and (most) Linux systems have a desktop environment running on top of the X11 Window System - typically Gnome or KDE. Are any of these sounding familiar?

If the answers to both questions are yes (yes - you are running on the physical Unix system; and yes - you are running a graphical user interface), then you may be able to enter into your xTerm the command "export DISPLAY=:0.0" (without the quotes).

If you are not physically attached to the Unix system, then you will need to provide a little more information before we can provide any more help.

If you are not running a graphical user interface on the Unix system, then there are ways around it, but they may be more trouble than they are worth.

Finally - for the SCJD project, you don't really need to test under Unix systems (although I applaud you for trying). One option you might want to consider is getting a live CD so you can run Linux on your own personal computer without actually installing Linux. You could then use this for testing.

Regards, Andrew

The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17410

This is most commonly seen when you have a web application that does graphics (such as charting) and you're running it on a server that isn't running a windowing system.

You can also encounter it if you attempt to run a Swing or AWT app on a command-line (non-windowed) machine.

DISPLAY is automatically set when you're running in a windowed session. You'd normally not change it.

For a webapp, there's an option to run "headless", but I don't have the documentation handy and I think it varies with whatever web application server you're using. Google will help - just look for "headless" and the name of your appserver (Tomcat or whatever).

For a standalone app, that's not going to work, since presumably the app depends on a GUI to work at all. In that case, you need to actually be running a windowing system. This might require installing the GUI and desktop packages, if they're not already installed.

An IDE is no substitute for an Intelligent Developer.
t tram

Joined: Mar 23, 2009
Posts: 3
Your question leaves out some important details. Are you telnetting in, or ssh into the unix machine froma Windows machine? That seems like the most common things that people would do. If that is the case and assuming that your unix server is already running the X Server, you will need a X windows manager on your Windows machine. One free one is Xming that you can download off the net. You will need to just google for it. Then download putty to be used with Xming. You will need to enable the X11 forwarding in the connection properties of putty.

If you use some other ssh clients, you might have to set up the DISPLAY environments differently.
For c-shell, you would use something like:
setenv DISPLAY

for bash:
export DISPLAY

Just remember to change the ip address to your unix machine.
I agree. Here's the link: http://aspose.com/file-tools
subject: Display variable on unix
jQuery in Action, 3rd edition