Java console error could not initialize class sun.awt.X11GraphicsEnvironment

Well this is another sanity post to save me next time I need to figure this problem out again, the issue is running a applet on a server in a Headless X11 environment.

There are java program settings to force checking that a X11 display is present and similar command line options to do the same, thowever this doesn't help when trying to run on your server console terminal in a Headless environment.

What the solution, you need to install on your Linux box the Xvfb package and set the appropriate DISPLAY shell variable in your console terminal.

Without a X11 screen you'll get an error similar to the following :-

Show Plain Text
Text code
  1. Exception in thread "main" java.awt.HeadlessException:
  2. No X11 DISPLAY variable was set, but this program performed an operation which requires it.
  3. at sun.awt.HeadlessToolkit.getScreenSize(HeadlessToolkit.java:261)
  4. ...
  5.  

To solve this issue you need to start the Xvfb virtual frame buffer software and set in your console terminal the corresponding display number to use, for example :-

Show Plain Text
Text code
  1. Xvfb :2&
  2. export DISPLAY=":2"

Then run your application and bobs your uncle...

Filed under: Java  Tags: Applet

0 Responses to “Java console error could not initialize class sun.awt.X11GraphicsEnvironment”

Sorry, comments have been closed for this post.