Running fop on an headless server

by Sebastien Mirolo on Sun, 31 Oct 2010

fop is a useful tool in the process of formatting documentation as pdf when you start with docbook marked-up documents. Unfortunately on some machine you end-up with the following result when running the tool.

fop -fo drop.fo -pdf drop.pdf
...
(.:13431): Gtk-WARNING **: cannot open display: 

As it turns out, fop relies on different java libraries. One of them, the SVG renderer batik uses the Java AWT framework and ultimately requires an X11 server being present.

There are thus a few alternatives to get rid of the problem. They either boil down to installing an X11 server or getting rid of the X11 dependency somehow. A popular (as far as google searches tell) solution out of the second category is to run the java virtual machine in headless mode using the following command line argument

java -Djava.awt.headless=true 

On Ubuntu 8.10 server, this fix did not work at first. The reason there lies in the Java Runtime Environment (JRE) installed by default. Ubuntu installs gcj, the GNU Java Implementation, and even though in theory it should support the java.awt.headless property, there are enough reports of major flaws in the GNU implementation that it does not seem surprising to fail here.

Fortunately there is a simple way to force the system to use the Sun (Now Oracle) Java Runtime.

sudo apt-get install sun-java6-jre
sudo update-alternatives --config java
fop --execdebug -fo drop.fo -pdf drop.pdf

Headless mode works and the pdfs can now be produced on the build machine.

by Sebastien Mirolo on Sun, 31 Oct 2010