views:

1245

answers:

7

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.

A: 

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.

Arcane
A: 

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

/usr/X11R6/lib

Nathan
A: 

The X11 libraries are already installed. I made Tomcat point to those libraries. But still the same headless exception is thrown.

Vicky
Please write this as a comment. This is not an answer to your question.
hlovdal
+1  A: 

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.

Fernando Miguélez
+2  A: 

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.

Suppressingfire
+1 because this seems to be the answer that Vicky acknowledges solved the issue.
Brandon DuRette
A: 

Thank You all for your help. Exporting the display for xvfb in tomcat's startup.sh worked for me.

Stackoverflow rocks...

Vicky
However your usage of stackoverflow does not rock... Currently you have asked 22 questions and never accepted any single answer. You have never written any answers to other people's questions and the few answers you have written to your own questions and should have been comments instead. Please consider contributing a bit back to stackoverflow.
hlovdal
A: 

Hi,

There is a next question that has come up from the Sys Admins. They are asking -

"Why does java1.5 now requires the explicit export DISPLAY in tomcat at all when java1.4 did not?"

So what has changed in java1.5 which is causing it to throw a java.awt.HeadlessException without the explicit export DISPLAY?

Is there a change in a way applets works in java1.5? Has Sun changed internal working of AWT or Swing in java1.5? What is the reason that java1.4 was able to see the xvfb libraries running on Unix but java1.5 cannot see without an explicit export DISPLAY?

Vicky
Ask a new, separate question for this.
mark