java.awt.HeadlessException - 未显示Applet

时间:2022-06-16 11:12:33

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.

我在HP Unix上使用Tomcat 5.5.23,JDK 1.5。我们有一个应用程序,当调用tomcat时启动一个applet。它在JDK 1.4之前工作正常。但现在我们已经转移到JDK 1.5并且applet没有启动。抛出的异常是 - java.awt.HeadlessException:没有设置X11 DISPLAY变量,但是该程序执行了一个需要它的操作。

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.

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

Any help would be appreciated.

任何帮助,将不胜感激。

5 个解决方案

#1


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.

奇怪..你正试图在tomcat中运行一个applet(我假设你正在谈论java.awt.Applet的一个子类)?通常这不起作用,因为没有显示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.

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

#2


-Djava.awt.headless=false

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

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

#3


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.

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

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.

所以现在的问题是,如果它正在使用Java 1.4,为什么它不适用于1.5?我敢打赌,鉴于Swing随着时间的推移获得的Java 1.2以来的性能提升,Sun已经将一些图形对象的管理转移到OS级别以提高性能。所以,如果你不能坚持1.4,那么你应该修改你的代码。

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

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

#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.

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

#5


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

您可能还必须安装x11库,或者至少明确地将路径导出到它们。

/usr/X11R6/lib

#1


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.

奇怪..你正试图在tomcat中运行一个applet(我假设你正在谈论java.awt.Applet的一个子类)?通常这不起作用,因为没有显示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.

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

#2


-Djava.awt.headless=false

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

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

#3


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.

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

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.

所以现在的问题是,如果它正在使用Java 1.4,为什么它不适用于1.5?我敢打赌,鉴于Swing随着时间的推移获得的Java 1.2以来的性能提升,Sun已经将一些图形对象的管理转移到OS级别以提高性能。所以,如果你不能坚持1.4,那么你应该修改你的代码。

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

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

#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.

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

#5


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

您可能还必须安装x11库,或者至少明确地将路径导出到它们。

/usr/X11R6/lib