java.lang.NoClassDefFoundError: sun/awt/X11GraphicsEnvironment 问题在 linux 上运行我们基于小程序的应用程序时面临

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1687898/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 17:36:36  来源:igfitidea点击:

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

java

提问by arunachalam

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 forums we came across solution of this issue by setting -Djava.awt.headless=true in JAVA_OPTS of run.conf file.

我们在扩展 javax.swing.JApplet 的应用程序中构建了小程序。最近我们在 linux 环境中运行时遇到了 X11GraphicsEnvironment 的问题,浏览各种论坛,我们通过在 run.conf 文件的 JAVA_OPTS 中设置 -Djava.awt.headless=true 来解决这个问题。

but this results in HeadlessException.

但这会导致 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.

最初,我们的客户端告诉我们在终端中使用命令 ssh -X 启动应用程序服务器,它曾经可以正常工作,但现在需要丢弃它。

Thanks in advance...

提前致谢...

回答by joev

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:

您确定 java.awt.headless 属性正确进入您的环境吗?出于某种原因,您的小程序是否打算在无头环境中运行?这是一个快速示例应用程序,演示了该标志的作用:

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:

当我在没有标志的情况下在 Linux 中运行它时:

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

When I run this in Linux with the flag:

当我在带有标志的 Linux 中运行它时:

$ 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:

此外,如果我取消设置 DISPLAY,并在没有标志的情况下运行,则会出现异常:

$ 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.access0(X11GraphicsEnvironment.java:52)
    ...

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

如果我然后设置标志,我会得到与上面 isHeadless:true 示例中相同的输出。

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

您应该更全面地描述您的环境,这将有助于诊断您的问题。

回答by Carl Smotricz

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.

如果确实没有 GUI,您只能将 Swing/AWT 应用程序作为“无头”运行。例如,我使用一个创建图形图表的包,但仅将其写入文件而不使用屏幕显示。

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.

如果您运行 GUI 应用程序,您需要提供一个屏幕来显示它。如果您在本地机器上运行它,那通常是“自动的”。如果您在远程机器上,则需要将 DISPLAY 环境变量设置为显示机器的主机地址,加上 :0 或类似的内容以指示屏幕编号。

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.

SSH 客户端(如 OpenSSL 或 Putty)可以在您连接到的机器的 shell 中自动为您设置此 DISPLAY 环境变量,然后当您在远程机器上启动应用程序时,您会在本地机器的监视器上看到 GUI。如果此过程出现问题,则会出现您所看到的那种错误。

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.

  • 在 SSH shell 中执行“echo $DISPLAY”,看看它是否已设置。

  • 试试“xeyes”,一个小的 X 程序,可以在屏幕上显示一双眼睛。如果它们出现,则说明一切正常,并且您的程序存在特定问题。