tags:

views:

1709

answers:

7
+4  Q: 

Fake X11 display?

I have a Java program using AWT which I would like to run on a headless system. The display for the program does nothing other than display stats. When the program finishes, it exits. There is no user interaction on the display. The program creates an output file which I use in my build system.

Is there a way to get the Java program to run without an X11 display configured? Can I force Java to run the program without trying to display anything? I do not have access to the source code (it is just .jar file), so I can't make modifications to the source.

Any thoughts on how I could get this to work?

+11  A: 

Xvfb can do what you ask for. I've not used it myself, but here is a link to wikipedia: http://en.wikipedia.org/wiki/Xvfb

Peter B. Bock
I used it once to run a headless openoffice, it works like a charm
Olivier
Hhhm, the java -Djava.awt.headless=true solution proposed below makes far more sense than installing some 3rd party software.
stephen mulcahy
Yeah, if that works it seems like a much better idea.
Peter B. Bock
Xvfb is hardly 3rd party software - it's part of a standard X11 distribution.
+4  A: 

Could also run Xvnc in a low resolution and color depth.

Joshua
Stupid downvote. Xvnc works out to be approximagely equal to Xvfb only you can connect to it if you finally end up needing to for debugging.
Joshua
+8  A: 

You can use a vncserver.

vncserver -display :1001 export DISPLAY=localhost:1001 java..

The added advantages is that you can actually view the gui using vncserver 'just in case'

Vardhan Varma
+18  A: 

The underlying question here is how to run Java applications without an X server; providing a "fake" X server is only one option. In Java 1.4 and up, you can do the following:

java -Djava.awt.headless=true

This allows applications which use AWT to run on headless systems even without an X server.

Charles Duffy
This looks like the best solution
hhafez
Note that this is not necessarily sufficient. For example even with this flag I get the following stack trace for a program which tries to use a JFrame:Exception in thread "main" java.awt.HeadlessException at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:159) at java.awt.Window.<init>(Window.java:431) at java.awt.Frame.<init>(Frame.java:403) at javax.swing.JFrame.<init>(JFrame.java:207)
Scott Bale
A: 

I've used with great success in the past the PJA libraries, they don't seem to be maintained anymore, but then again, just just want to run...

webclimber
+1  A: 

As mentioned by Charles Duffy the traditional method is to tell Java to go headless.

Note that you can always mount the jar in Eclipse and use jad+jadclipse to see what it actually does, and perhaps even override a class if you need to by putting another class-file in "front" of it in the classpath.

A facility that might be relevant if the program uses Java2D is that newer Java versions use optimizations in the X11 server to render faster. This alone might be a reason to devote an X11 server attached to a high performance graphics card to your graphics processing.

Thorbjørn Ravn Andersen
A: 

This is slightly wrong, you don't put -display on it, that tries to start the app on the display specified

vncserver -display :1001

you only need to do

vncserver :1001

Robin