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.
(default) 11 queries took 3 ms
NrQueryErrorAffectedNum. rowsTook (ms)
1DESCRIBE `posts`17171
2DESCRIBE `comments`11111
3DESCRIBE `tags`221
4DESCRIBE `categories`220
5DESCRIBE `posts_tags`220
6DESCRIBE `categories_posts`220
7SELECT `Post`.`id`, `Post`.`url`, `Post`.`title`, `Post`.`icon`, `Post`.`metadesc`, `Post`.`metakeys`, `Post`.`categories`, `Post`.`tease`, `Post`.`body`, `Post`.`private_body`, `Post`.`created`, `Post`.`modified`, `Post`.`status`, `Post`.`allow_comments`, `Post`.`tags`, `Post`.`hitcount`, `Post`.`hitcount_rss` FROM `posts` AS `Post` WHERE `Post`.`url` = 'java-console-error-could-not-initialize-class-sun-awt-x11graphicsenvironment' LIMIT 1110
8SELECT `Comment`.`id`, `Comment`.`post_id`, `Comment`.`body`, `Comment`.`author`, `Comment`.`url`, `Comment`.`email`, `Comment`.`ip`, `Comment`.`status`, `Comment`.`junk_score`, `Comment`.`created`, `Comment`.`modified` FROM `comments` AS `Comment` WHERE `Comment`.`status` = 2 AND `Comment`.`post_id` = (83) 000
9SELECT `Tag`.`id`, `Tag`.`tag`, `PostsTag`.`post_id`, `PostsTag`.`tag_id` FROM `tags` AS `Tag` JOIN `posts_tags` AS `PostsTag` ON (`PostsTag`.`post_id` = 83 AND `PostsTag`.`tag_id` = `Tag`.`id`) 110
10SELECT `Category`.`id`, `Category`.`category`, `CategoriesPost`.`post_id`, `CategoriesPost`.`category_id` FROM `categories` AS `Category` JOIN `categories_posts` AS `CategoriesPost` ON (`CategoriesPost`.`post_id` = 83 AND `CategoriesPost`.`category_id` = `Category`.`id`) 110
11UPDATE `posts` AS `Post` SET `Post`.`hitcount` = Post.hitcount + 1 WHERE `Post`.`id` = 8310