java.awt.HeadlessException - 小程序未显示

发布于 2024-07-11 16:23:30 字数 358 浏览 3 评论 0原文

我在 HP Unix 上使用 Tomcat 5.5.23、JDK 1.5。 我们有一个应用程序,当从 tomcat 调用时,它会启动一个小程序。 在 JDK 1.4 之前它都运行良好。 但现在我们已经迁移到 JDK 1.5,并且小程序无法启动。 抛出的异常是 - java.awt.HeadlessException: 未设置 X11 DISPLAY 变量,但该程序执行了需要该变量的操作。

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

任何帮助,将不胜感激。

I am using Tomcat 5.5.23, JDK 1.5 on HP Unix. We have an application which when invoked form tomcat starts an applet. It was working fine till JDK 1.4. But now we have moved to JDK 1.5 and the applet does not start. The exception thrown is -
java.awt.HeadlessException:
No X11 DISPLAY variable was set, but this program performed an operation which requires it.

I then added JAVA_OPTS="-Djava.awt.headless=true" to catalina.sh file. But still I get the same Headless exception, but this time without the X11 Display message.

Any help would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

溺孤伤于心 2024-07-18 16:23:30

奇怪..你试图在tomcat中运行一个小程序(我假设你正在谈论java.awt.Applet的子类)? 一般来说,这是行不通的,因为没有显示器可以显示小程序。

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

Odd.. you're trying to run an applet (I assume you are talking about a subclass of java.awt.Applet) inside tomcat? Generally this won't work because there's no display on which to display the applet.

Assuming you don't want the applet to display anywhere and you just want to execute some portion of it programmatically, you may be able to get by using a virtual X server such as Xvfb or Xvnc. Once you have Xvfb or Xvnc running on your host running tomcat, you might try to set the DISPLAY inside the tomcat startup scripts to use the display of the virtual X server.

稀香 2024-07-18 16:23:30
-Djava.awt.headless=false

在 Tomcat 启动脚本中添加上述内容。 100% 有效

-Djava.awt.headless=false

add above in your Tomcat startup script. it will work 100%

不奢求什么 2024-07-18 16:23:30

您可能在 Java 代码中使用了一些无法在无头系统上工作的东西,例如图形组件(Swing 对象、图像等)。 其中一些组件不是由 Java 直接处理,而是由底层平台(Windows 内核本身或 Unix 上的 X-Window 服务器)处理。 这样,应用程序的整体性能就得到了提升。

所以现在的问题是,如果它可以在 Java 1.4 上运行,为什么它不能在 1.5 上运行呢? 我敢打赌,鉴于自 Java 1.2 以来 Swing 的性能随着时间的推移而得到提升,Sun 已将一些图形对象的管理移至操作系统级别以提高性能。 所以如果你不能坚持1.4,那么你应该修改你的代码。

这篇好文章将帮助您了解如何修改您的应用程序使其无头友好。

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.

做个少女永远怀春 2024-07-18 16:23:30

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

Applets are going to have a hard-time running server-side. They are designed to run inside of a container, such as a web browser. The exception is getting thrown most likely because the applet is trying to draw it's GUI -- and the server is providing no support for this. I'm surprised that it worked in JDK 1.4 -- I don't know what changed between the two revisions which would have affected this.

泪之魂 2024-07-18 16:23:30

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

/usr/X11R6/lib

You may also have to install the x11 libraries, or at least explicitly export the path to them.

/usr/X11R6/lib

欢你一世 2024-07-18 16:23:30
  1. 使用您喜欢的文本浏览器打开 $CATALINA_HOME/bin/startup.sh 文件
  2. 将此行 export CATALINA_OPTS="$CATALINA_OPTS -Djava.awt.headless=false" 粘贴到开头文件的
  3. 保存并关闭文件
  4. 重新启动 Tomcat
  1. Open $CATALINA_HOME/bin/startup.sh file with your preferred text browser
  2. Paste this line export CATALINA_OPTS="$CATALINA_OPTS -Djava.awt.headless=false" at the beginning of the file
  3. Save and close the file
  4. Restart Tomcat
无敌元气妹 2024-07-18 16:23:30

在带有数据库访问的 Spring Boot 中,当您指定星号:**** 作为用户名和密码时,它会尝试提示用户输入用户名和密码(您没看错),如果它不是一个,它将抛出此 HeadlessException图形用户界面应用程序。

In spring boot with database access, when you specify asterisks: **** as username and password, it will try to prompt the user for a username and password (you read that right), and it will throw this HeadlessException if it's not a gui application.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文