2

我在 HP Unix 上使用 Tomcat 5.5.23、JDK 1.5。我们有一个应用程序,当从 tomcat 调用时会启动一个小程序。在 JDK 1.4 之前它工作正常。但是现在我们已经迁移到 JDK 1.5 并且小程序无法启动。抛出的异常是 - java.awt.HeadlessException: No X11 DISPLAY variable was set,但是这个程序执行了一个需要它的操作。

然后我将 JAVA_OPTS="-Djava.awt.headless=true" 添加到 catalina.sh 文件中。但我仍然得到相同的无头异常,但这次没有 X11 显示消息。

任何帮助,将不胜感激。

4

7 回答 7

2

奇怪..您正在尝试在 tomcat 中运行一个小程序(我假设您正在谈论 java.awt.Applet 的子类)?通常这不起作用,因为没有显示小程序的显示器。

假设您不希望小程序显示在任何地方并且您只想以编程方式执行它的一部分,您可以通过使用虚拟 X 服务器(例如 Xvfb 或 Xvnc)来获得。一旦在运行 tomcat 的主机上运行了 Xvfb 或 Xvnc,您可能会尝试在 tomcat 启动脚本中设置 DISPLAY 以使用虚拟 X 服务器的显示。

于 2009-01-19T16:54:54.953 回答
2
-Djava.awt.headless=false

在您的 Tomcat 启动脚本中添加上述内容。它将工作 100%

于 2012-07-10T14:19:55.887 回答
1

You are maybe using something in your Java code that can not work on a headless system, such as graphics components (Swing objects, images, etc.). Some of these components, instead of being directly handled by Java, are handled by underlying platform (Windows kernel itself or X-Window server on Unix). This way the overall performance of application is boosted.

So the question now is, ok if it was working on Java 1.4, why doesn't it work on 1.5? My bet, given the peformance boost since Java 1.2 that Swing has received over time, is that Sun has moved the management of some graphic objets to OS level to increase performance. So if you can not stick to 1.4, then you should revise your code.

This good article will help you understand how to modify your application to make it headless-friendly.

于 2009-01-18T21:57:51.130 回答
0

小程序将很难在服务器端运行。它们被设计为在容器内运行,例如 Web 浏览器。最有可能抛出异常是因为小程序试图绘制它的 GUI——而服务器对此不提供支持。我很惊讶它在 JDK 1.4 中工作——我不知道这两个版本之间发生了什么变化会影响到这一点。

于 2009-01-14T23:23:24.947 回答
0

您可能还必须安装 x11 库,或者至少显式导出它们的路径。

/usr/X11R6/lib

于 2009-01-15T07:39:33.417 回答
0
  1. $CATALINA_HOME/bin/startup.sh使用您喜欢的文本浏览器打开文件
  2. 将此行粘贴export CATALINA_OPTS="$CATALINA_OPTS -Djava.awt.headless=false"到文件的开头
  3. 保存并关闭文件
  4. 重启Tomcat
于 2019-08-25T06:40:05.873 回答
0

在具有数据库访问权限的 Spring Boot 中,当您指定星号:**** 作为用户名和密码时,它会尝试提示用户输入用户名和密码(您没看错),如果不是gui 应用程序。

于 2021-09-03T14:02:50.810 回答