Monday, 21 January 2008

Use Xvfb (fake xserver) to avoid AWT HeadlessException

Today I had a problem at work, one java application was supposed to be desktop environment agnostic but because it has bugs it throws AWT HeadlessException on ubuntu-server. As you know ubuntu-server doesnt have xserver installed.

I though that I could find an xserver implementation, which would be dummy and would fool my java application that is it running in desktop environment.

As it turns out ubuntu has in its repositories Xvfb type: sudo apt-get install xvfb
I dont think you even need xserver-xorg for this to work.

Example usage:
Xvfb :1 -screen 0 1024x768x8 &
export DISPLAY=":1"
java java_app.jar

2 comments:

Kazik Pogoda said...

Have you tried:

java -Djava.awt.headless=true

AFAIR debian's tomcat sets this property by default.
here are some hints.

However having real X server running on decent graphic card can probably give some acceleration for Java2D rendering. AFAIR nvidia has some extra acceleration in their linux drivers. It could be the only reason to have good graphic card put in server machine. :)

winnetou said...

Thanks, I didnt know I could you this option.