0

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.

GmodCake
  • 427
  • 3
  • 11
  • 24
  • 1
    Do you actually need a display at all? If not you can run the JVM with `-Djava.awt.headless=true` – fge Mar 06 '15 at 16:36
  • 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 Mar 06 '15 at 16:38
  • Unless you clear it, ProcessBulder will pass the caller's environment to the called process. – stark Mar 06 '15 at 16:40
  • What do you mean ? They're on the same environment – GmodCake Mar 06 '15 at 16:41
  • Can you be more precise about "doesn't work"? – fge Mar 06 '15 at 16:45
  • I get this : Exception in thread "main" java.lang.ExceptionInInitializerError at com.prodevcoind.myapp.gui.MainDesktop.main(MainDesktop.java:198) Caused by: java.awt.HeadlessException – GmodCake Mar 06 '15 at 16:56

2 Answers2

1

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

fge
  • 119,121
  • 33
  • 254
  • 329
0

So this actually solved the problem :

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

GmodCake
  • 427
  • 3
  • 11
  • 24