问题
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:
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"
来源:https://stackoverflow.com/questions/39388037/java-awt-requires-x11-how-to-use-xvfb-ubuntu-14-04