Fake X11 display?
Asked Answered
C

7

15

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?

Cobaltic answered 30/1, 2009 at 4:1 Comment(0)
U
31

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.

Underpay answered 30/1, 2009 at 4:41 Comment(3)
This looks like the best solutionArlettearley
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)Motorbike
@ScottBale, I agree that it's not necessarily sufficient. OTOH, I also would call it the right place to start first.Underpay
D
16

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

Dicks answered 30/1, 2009 at 4:9 Comment(4)
I used it once to run a headless openoffice, it works like a charmPyrogallol
Hhhm, the java -Djava.awt.headless=true solution proposed below makes far more sense than installing some 3rd party software.Copland
Xvfb is hardly 3rd party software - it's part of a standard X11 distribution.Gladiate
Yup. This is definitely the right thing to do when -Djava.awt.headless=true doesn't work. I'd argue that -Djava.awt.headless=true is the right place to start, though, given the resource-consumption differences.Underpay
L
16

You can use a vncserver.

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

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

Launcher answered 30/1, 2009 at 4:30 Comment(0)
I
6

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

Internal answered 30/1, 2009 at 4:11 Comment(1)
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.Internal
U
1

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.

Understudy answered 20/2, 2009 at 17:2 Comment(0)
J
0

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...

Jenisejenkel answered 30/1, 2009 at 5:24 Comment(0)
R
0

I was able to get headless mode in OpenJFX with the command line arguments

-Dglass.platform=Monocle -Dmonocle.platform=Headless -Dprism.order=sw
Rubberneck answered 28/7, 2016 at 4:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.