X and Java

My servlets work on XP or Windows 2000, but not on Solaris. Why?

To generate an image, KavaChart employs various classes in Java's AWT package. Java's AWT package maps Java abstractions into specific operating system methods by using something called peer classes. These peer classes are usually created using native code (hence "native peer methods") for performance purposes. Windows implementations use code that calls the Windows GDI, Macintosh the Mac Toolbox, and Unix implementations use Xlib.

If you're using JDK 1.4 or newer, this means you should set the System property "java.awt.headless" to "true". From the command line:

	java ... -Djava.awt.headless=true ...

For more information on what's going on, or for alternatives that work with earlier versions of Java, see below:

Graphics operations generally require actual display hardware of some sort on the server, even though nothing will actually appear on the screen. For Windows and NT servers, this isn't a problem. Unix servers must have access to an X-windows display. The display needn't be local (although performance may degrade if it's not), and it can even be a "virtual" display, such as the xvfb (X Windows Virtual Framebuffer), which can be freely downloaded as an RPM from most Linux sites.

A binary Solaris version of xvfb can be found here, along with usage and installation notes.

AIX releases include a fileset called x11.vfb that works the same as xvfb. Chapter 6.1 of this document describes installation and compatibility issues for this fileset.

Bottom line? For Unix, your DISPLAY environment variable must point to an actual or virtual X server.

It's also possible to replace these peer classes with non-native, pure Java implementations. We suggest you try PJAToolkit, a free download from ETeks if you want to try a pure Java approach. If your native language is French, use this link.


For some Java web servers (e.g. Apache JServ and Tomcat environments), setting the DISPLAY environment variable is a bit obscure. For Apache servers, use the wrapper.env file to specify your environment.

JDK 1.4 implements a "Headless Support" option along with new GraphicsEnvironment methods, and should run without the X windows requirement. See this link for more information: http://java.sun.com/j2se/1.4/docs/guide/awt/AWTChanges.html#headless


Some additional X-windows notes:

  • When making a connection to an X server, one specifies a display number and a screen number, in addition to the hostname of the server. The default connection is usually "localhost:0.0", which means "the X server running on localhost, for display 0 and screen 0". This default is usually changed for a particular shell by modifying the environment variable "DISPLAY". For example, "setenv DISPLAY goldfish:1.0" would change the default X server to the one running on the machine "goldfish" for display 1, screen 0. Most X applications (also called "client processes") also support a -display flag, which lets you override the DISPLAY environment directly.
  • X Servers have a modicum of security built in, so that "foreign" clients can't connect to an X server unless permission is granted, using the xhost program. Consult your system's documentation for xhost specifics, but usually "xhost +" will instruct the default X server to permit connections from any other host or process.
  • Usually, xvfb is started as the server for DISPLAY localhost:1.0, so you'll want to make sure you set your environment correctly for Java services.
  • Some X servers default to a 256 color PseudoColor Visual model, which may yield poor color management when generating images.
  • You can set up your X windows (and xvfb) configuration to be set at startup by modifying the appropriate files in /etc/rc*. Systems vary in startup configuration, so leave this task to your system administrator.
  • If you're using your local display's X Server to make sure everything's working, and then log out, you'll be unable to connect to that server after logging out.

    Return to Search Page