Home

Question

How can images be generated by Java servlets when an associated X server is not available?

Answer

In order to generate images in Java the awt toolkit must be used, this in turn requires access to the native windowing system, which in the case of Unix is X11. To overcome this Xvfb - virtual framebuffer X server for X Version 11 can be used.

Xvfb is an X server that can run on machines with no display hardware and no physical input devices. It emulates a dumb framebuffer using virtual memory, providing an unobtrusive way to run applications that don't really need an X server but insist on having one anyway. It can be found as part of X11 Release 6.4, a version of which is available from XFree86 .

Xvfb can be started by a command similar to the following, where the actual screen dimensions may have to be adjusted to suit your requirements

  /opt/X11R6/bin/Xvfb :1 -screen 0 640x480x24 -fbdir /tmp &

This configuration has been successfully used on Solaris (Intel) 2.6 running Tomcat as the servlet container generating JPEG images.