Answer
The Sun AWT classes on Unix and Linux have a dependence on the X Window System: when you use the classes, they expect to load X client libraries and be able to talk to an X display server. This makes sense if your client has a GUI... unfortunately, it's required even if your client uses AWT but does not have a GUI. For example, you need access to an X server to use the java.awt.BufferedImage class.
Access to an X display server means a few things:
- An X display server is running somewhere.
- The environment in which you run Java includes an environment variable DISPLAY identifying how to reach the server.
- There are no security settings in the server to prevent your client from opening a connection.
In general, if you're running your program from a terminal within the X Window System, all these things are true and the program just works. If you can run other X applications, like xterm or xclock, you should be able to run your Java AWT application.
In non-graphical environments, such as a servlet engine, your program may not know how to find or connect to an X display server. A common solution here is to run a special non-display version of the X display server, Xvfb, and set DISPLAY to point to it.
New information for JDK1.4: JDK1.4 evidently includes a new property that will allow the AWT to run in a headless (without a display) environment. This setting is supposed to solve the problem: java.awt.headless=true
Is this item
helpful? yes no
Previous votes Yes: 4 No: 0
|
|
Comments and alternative answers
 |
Java 1.4 headless - not quite there.
Mike Bremford, Mar 14, 2002 [replies:2]
Unfortunately we've just been testing the headless support with the Java 1.4.0 release on Linux, and it's not quite what we expected.
It's possible to run many AWT methods now without requiring a running X server, although an equal number will throw a java.awt.HeadlessException. In particular, the oft-quoted method for creating a server side image:
Frame f = new Frame();
f.addNotify();
Image i = f.createImage(width,height);
will throw an Exception when running headless. You can easily replace this with:
Image i = new BufferedImage(width,height, BufferedImage.TYPE_INT_ARGB);
which gives identical results however.
So far so good. What's not obvious though is that even though Java 1.4 doesn't need an X server to connect to, it still needs X11 installed. The headless toolkit still makes calls to a native library (jre/lib/i386/libawt.so), which requires a number of libraries which are part of the X11 distribution. For those running RedHat 7.1 or later, these libraries are all in the XFree86-devel package.
Almost there, Sun, but not quite...
Is this item
helpful? yes no
Previous votes Yes: 1 No: 0
|
|

|
 |
 |
Re: Java 1.4 headless - not quite there.
Guilherme Silva, Mar 2, 2004 [replies:1]
Hi all,
Unfortunately, setting this property using this command:
System.setProperty("java.awt.headless", "true");
inside a JSP didn't solve the problem.
It only works in a console java class.
Is this item
helpful? yes no
Previous votes Yes: 0 No: 0
|
|

|
 |
Must run as root (sudo)
Joseph Schmoley, Aug 12, 2008
I'm running an X11 system on Centos 5.2 final (2.6.18-92.1.6.el5), logged in via X, can run xclock and other X GUI apps no problem, but I still experienced this error message.
I'm not sure if this is the actual fix but it worked for me... my user account (not root) on this machine has sudo privileges. If I issue the same command with sudo, the applet window appears without a problem.
Hope this helped someone.
-Jac
Is this item
helpful? yes no
Previous votes Yes: 0 No: 0
|
|

|
|