Linux X11 Libraries for Headless Mode

Java 1.4 and higher include support for “headless” mode, allowing many AWT operations to be used on machines that do not have a keyboard, mouse, or display. Launching a virtual machine in headless mode is simple: Just specify the java.awt.headless property on the command line:

java -Djava.awt.headless=true …

Headless mode is useful, for example, for rendering images from servlets running on a dedicated server. More details on headless mode can be found on Sun’s AWT Enhancements page.

Dedicated servers and virtual dedicated servers (or “virtual private servers”) are an increasingly affordable way to host java (and other) systems. While many dedicated server vendors offer Linux as an option, the default installations often lack X11 support. Fortunately, it is only necessary to install a subset of the X11 libraries to allow headless mode Java applications to function properly.




The listing below shows the minimal set of libraries needed to use JDK 1.4.2 under RedHat Linux 9.0, tested on a virtual dedicated server. The files can simply be uploaded from a full RedHat installation (on the same architecture) to /usr/X11R6/lib:




lrwxrwxrwx    1 root     root       13 Aug 30 20:44 libICE.so -> libICE.so.6.3
lrwxrwxrwx    1 root     root       13 Aug 30 20:44 libICE.so.6 -> libICE.so.6.3
-rwxr-xr-x    1 root     root    82080 Aug 30 20:44 libICE.so.6.3
lrwxrwxrwx    1 root     root       12 Aug 30 20:43 libSM.so -> libSM.so.6.0
lrwxrwxrwx    1 root     root       12 Aug 30 20:43 libSM.so.6 -> libSM.so.6.0
-rwxr-xr-x    1 root     root    31544 Aug 30 20:42 libSM.so.6.0
lrwxrwxrwx    1 root     root       13 Aug 30 20:40 libX11.so -> libX11.so.6.2
lrwxrwxrwx    1 root     root       13 Aug 30 20:40 libX11.so.6 -> libX11.so.6.2
-rwxr-xr-x    1 root     root   911288 Aug 30 20:40 libX11.so.6.2
lrwxrwxrwx    1 root     root       14 Aug 30 20:28 libXext.so -> libXext.so.6.4
lrwxrwxrwx    1 root     root       14 Aug 30 20:28 libXext.so.6 -> libXext.so.6.4
-rwxr-xr-x    1 root     root    51632 Aug 30 20:28 libXext.so.6.4
lrwxrwxrwx    1 root     root       12 Aug 30 20:28 libXp.so -> libXp.so.6.2
lrwxrwxrwx    1 root     root       12 Aug 30 20:28 libXp.so.6 -> libXp.so.6.2
-rwxr-xr-x    1 root     root    26788 Aug 30 20:28 libXp.so.6.2
lrwxrwxrwx    1 root     root       12 Aug 30 20:29 libXt.so -> libXt.so.6.0
lrwxrwxrwx    1 root     root       12 Aug 30 20:29 libXt.so.6 -> libXt.so.6.0
-rwxr-xr-x    1 root     root   306428 Aug 30 20:28 libXt.so.6.0
lrwxrwxrwx    1 root     root       14 Aug 30 20:37 libXtst.so -> libXtst.so.6.1
lrwxrwxrwx    1 root     root       14 Aug 30 20:37 libXtst.so.6 -> libXtst.so.6.1
-rwxr-xr-x    1 root     root    17712 Aug 30 20:35 libXtst.so.6.1



Figure 1. Listing of X11 libraries in /usr/X11R6/lib

Figure two shows an example of commands that can be used to transfer the files from a full installation to another server.



On the full installation, build a tar archive of the libraries and transfer them to the remote server:


csh> cd /usr/X11R6/lib
csh> /bin/tar cvzf /tmp/x11-libs.tgz libICE.so libICE.so.6 libICE.so.6.3 \
    libSM.so libSM.so.6 libSM.so.6.0 libX11.so libX11.so.6 libX11.so.6.2 \
    libXext.so libXext.so.6 libXext.so.6.4 libXp.so \
    libXp.so.6 libXp.so.6.2 libXt.so libXt.so.6 libXt.so.6.0  \
    libXtst.so libXtst.so.6 libXtst.so.6.1
csh> scp /tmp/x11-libs.tgz server.domain.com:/tmp/
csh> rm /tmp/x11-libs.tgz

Then log into the remote server, use su to become root, and untar the archive:


csh> su
csh# mkdir -p /usr/X11R6/lib
csh# cd /usr/X11R6/lib
csh# tar xvzf /tmp/x11-libs.tgz
csh# rm /tmp/x11-libs.tgz



Figure 2. Transferring the libraries between machines