2

I Have a java application that requires X11 DISPLAY variable, the exception I am getting is:

    Caused by: java.awt.HeadlessException:
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
        at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:204)
        at java.awt.Window.<init>(Window.java:536)
        at java.awt.Frame.<init>(Frame.java:420)

I've installed Xvfb on the ubuntu machine:

root      1470  1469  0 02:40 pts/3    00:00:00 Xvfb :1 -screen 0 1152x900x8

But I am still getting this error.

When I start Xvfb I am getting the following response:

Initializing built-in extension Generic Event Extension
Initializing built-in extension SHAPE
Initializing built-in extension MIT-SHM
Initializing built-in extension XInputExtension
Initializing built-in extension XTEST
Initializing built-in extension BIG-REQUESTS
Initializing built-in extension SYNC
Initializing built-in extension XKEYBOARD
Initializing built-in extension XC-MISC
Initializing built-in extension SECURITY
Initializing built-in extension XINERAMA
Initializing built-in extension XFIXES
Initializing built-in extension RENDER
Initializing built-in extension RANDR
Initializing built-in extension COMPOSITE
Initializing built-in extension DAMAGE
Initializing built-in extension MIT-SCREEN-SAVER
Initializing built-in extension DOUBLE-BUFFER
Initializing built-in extension RECORD
Initializing built-in extension DPMS
Initializing built-in extension Present
Initializing built-in extension DRI3
Initializing built-in extension X-Resource
Initializing built-in extension XVideo
Initializing built-in extension XVideo-MotionCompensation
Initializing built-in extension SELinux
Initializing built-in extension GLX
[dix] Could not init font path element /usr/share/fonts/X11/cyrillic, removing from list!
[dix] Could not init font path element /usr/share/fonts/X11/100dpi/:unscaled, removing from list!
[dix] Could not init font path element /usr/share/fonts/X11/75dpi/:unscaled, removing from list!
[dix] Could not init font path element /usr/share/fonts/X11/Type1, removing from list!
[dix] Could not init font path element /usr/share/fonts/X11/100dpi, removing from list!
[dix] Could not init font path element /usr/share/fonts/X11/75dpi, removing from list!

and It doesn't return back to me, so I press 'CTRL + C' to take back control, but after looking at 'ps aux | grep Xvfb' I can see the process is running, so I am not sure if it worked or not.

Any help would be greatly appreciated.

Thanks

1 Answers1

0

You aren't getting an error, those are warning messages about old fonts. Start the virtual X server in the background (and/or with nohup) like

 nohup Xvfb :1 -screen 0 1152x900x8 &

And then, to use it, set your display to :1 on localhost like

 export DISPLAY="localhost:1"
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
  • It is working when I am trying to run a jar with a command line, but I am trying to use this in a server application, using tomcat as the server, and I'm getting the same error in the web application, should I change anything to make it work? – Alex Odesser Sep 08 '16 at 10:18
  • Set the display variable in the script you use to start tomcat. – Elliott Frisch Sep 08 '16 at 10:22
  • sorry, I don't know what you mean by the variable in the script i use to start tomcat – Alex Odesser Sep 08 '16 at 10:25
  • @AlexOdesser How are you running tomcat? – Elliott Frisch Sep 08 '16 at 22:22
  • using tomcat.conf from /etc/init/ , and then just 'sudo service tomcat start' – Alex Odesser Sep 10 '16 at 07:25
  • @AlexOdesser There is a script somewhere that invokes java. That script needs to be modified to use xvfb. Also, you might modify it to start and stop xvfb. – Elliott Frisch Sep 10 '16 at 07:30
  • Here is the JAVA_OPTS I have in the tomcat config file: env JAVA_OPTS="-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom" , should I just add "Xvfb :1 -screen 0 1152x900x8" to this option , or did you mean something else, sorry I haven't done anything like that before, so I am a bit lost here. – Alex Odesser Sep 10 '16 at 20:19
  • No. `JAVA_OPTS` is a different environment variable. Add `export DISPLAY="localhost:1"` on the line before setting JAVA_OPTS. – Elliott Frisch Sep 10 '16 at 21:12
  • I've added the export DISPLAY to the tomcat.conf , but it still isn't working, should I start Xvfb as a normal service in the background or should I start it another way so it would work with the tomcat service? – Alex Odesser Sep 11 '16 at 10:26