0
votes

I'm aware that this is a recurrent question but I haven't found any answer yet.

I'm on a linux server (Ubuntu 14.04 LTS) and I have a java application that calls another one to do some operation, the first one runs with no problem, but the second one use GUI and when I call it I get the infamous error " No X11 DISPLAY variable was set, but this program performed an operation which requires it. ". I already have a Xvfb instance running and I exported DISPLAY.

Xvfb :99 &
export DISPLAY=:99

If I do

echo $DISPLAY

I get :99

I can run the called java application by command line and it works, but when it's another java application that calls it, it doesn't work. Why it doesn't "see" the DISPLAY variable when I call the jar from another java application ? And how do I fix this ?

NOTE : I use ProcessBuilder to call it.

2
Do you actually need a display at all? If not you can run the JVM with -Djava.awt.headless=true - fge
No I don't require to see the display, but the application needs it (poorly coded) and running it with -Djava.awt.headless=true doesn't work either. - GmodCake
Unless you clear it, ProcessBulder will pass the caller's environment to the called process. - stark
What do you mean ? They're on the same environment - GmodCake
Can you be more precise about "doesn't work"? - fge

2 Answers

1
votes

Since you use a ProcessBuilder and don't require a display, you may try and do this before you .start() the process:

pb.environment().remove("DISPLAY");

Yes, that's right, environment() returns a read write view of the process' environment variables...

0
votes

So this actually solved the problem :

processBuilder.environment().put("DISPLAY", ":99");