开发者

java.lang.NoClassDefFoundError: sun/awt/X11GraphicsEnvironment issuses faced while running our applet based app on linux

We have built applet in our application extending javax.swing.JApplet. of late we have been facing issue of X11GraphicsEnvironment while running in linux environment, browsing through various foru开发者_如何学Pythonms we came across solution of this issue by setting -Djava.awt.headless=true in JAVA_OPTS of run.conf file.

but this results in HeadlessException.

initally our client told us to start the app server in a terminal with command ssh -X , it used to work fine, but now it needs to be discarded.

Thanks in advance...


Are you sure that java.awt.headless property is getting into your environment correctly? Is your applet intended to be run in a headless environment for some reason? Here's a quick sample application that demonstrates what that flag does:

import java.awt.GraphicsEnvironment;

public class GETest {
  public static void main(String[] args) {
    GraphicsEnvironment ge = 
      GraphicsEnvironment.getLocalGraphicsEnvironment();

    System.out.println("class: " + ge.getClass());
    System.out.println("isHeadless:" + ge.isHeadless());
  }
}

When I run this in Linux without the flag:

$ java GETest
class: class sun.awt.X11GraphicsEnvironment
isHeadless:false

When I run this in Linux with the flag:

$ java -Djava.awt.headless=true GETest
class: class sun.java2d.HeadlessGraphicsEnvironment
isHeadless:true

Further, if I unset DISPLAY, and run without the flag, I get the exception:

$ unset DISPLAY
$ java -Djava.awt.headless GETest
Exception in thread "main" java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
    at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
    at sun.awt.X11GraphicsEnvironment.access$100(X11GraphicsEnvironment.java:52)
    ...

If I then set the flag, I get the same output as I do in the isHeadless:true example above.

You should describe your environment more fully, that would help in diagnosing your problem.


You can only run a Swing/AWT app as "headless" if there is truly no GUI. For example, I use a package that creates a graphical chart, but writes it only to a file without using an on-screen display.

If you run a GUI application, you need to provide a screen to display it on. If you're running it on your local machine, that's usually "automatic". If you're on a remote machine, you need to have the DISPLAY environment variable set to the host address of your displaying machine, plus :0 or something similar to indicate a screen number.

SSH clients like OpenSSL or Putty can automatically set this DISPLAY env variable for you in the shell of the machine you connect to, and then when you start up the app on the remote machine you see the GUI on your local machine's monitor. If something goes wrong with this process, you get the kind of errors you're seeing.

Some things to try:

  • do "echo $DISPLAY" in your SSH shell, see if it's set.

  • try "xeyes", a little X program to display a pair of eyes on the screen. If they show up, then things are set up OK and there's a problem particular to your program.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜