Dynamic images & servlet config.

I apologize for the cross-posting. I already put this up on the main sun forums, but there’s a few slightly sharper graphics people here on the JGO forums. Any help would be appreciated.

Okay, so I’m creating a web-based game, and I’m doing just a wee bit of dynamic image creation. Up to this point everything has been working fine on tomcat 4.something, Java 1.4.2 running on Gentoo. I’m upgrading to Suse Professional 9.3, java 5 and Tomcat 5.0.30.

Everything seems to be working well, but my dynamic image generation keeps throwing one of the two following stack traces, seemingly at random:

java.lang.NoClassDefFoundError
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Class.java:164)
java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:68)
java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1141)
edited - myclass.performAction(edited - myclass.java:66)
edited - mysuperclass*.execute(edited - mysuperclass.java:86)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

OR

java.lang.InternalError: Can’t connect to X11 window server using ‘127.0.0.1:0’ as the value of the DISPLAY variable.
sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
sun.awt.X11GraphicsEnvironment.access$000(X11GraphicsEnvironment.java:53)
sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:142)
java.security.AccessController.doPrivileged(Native Method)
sun.awt.X11GraphicsEnvironment.(X11GraphicsEnvironment.java:131)
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Class.java:164)
java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:68)
java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1141)
edited - myclass.performAction(edited - myclass.java:66)
edited - mysuperclass.execute(edited - mysuperclass.java:86)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

Which error gets thrown depends on whether or not I’ve JUST bounced tomcat. At least . . . that’s the only factor I can figure out. (When I restart tomcat, I get the second stack trace, otherwise, the first.) It SEEMS as though I don’t have X installed, but it’s not only installed, it’s running. Here’s the output of ps -ef just to prove it:

root 6873 5967 0 03:53 ? 00:00:11 /usr/X11R6/bin/X -br -nolisten tcp :0 vt7 -auth /var/lib/xdm/authdir/authfiles/A:0-bI32tt

While I’m doing most of this configuration remotely on the command line via SSH, KDE is up and working, and was used for the initial install of all the software. Oh, and on that second stack trace, I’ve tried every value I can think of for the DISPLAY environment variable. localhost:0, :0 . . . nothing at all, I’m stumped on that count.

Frankly, I’m baffled. I’ve tried just running headless, but as I’m actually using BufferedImages, it seems that I cannot simply run a headless environment, or at least, I get exactly the same errors. Any suggestions?

We use headless boxes with WebLogic producing dymnamic images I think our display setting is:

export DISPLAY=:0.0
or maybe
export DISPLAY=localhost:0.0

I think the machines have Xvfb installed which can be found at http://www.xfree86.org/

here is some other random info:

http://javatechniques.com/public/java/docs/hosting/headless-java-x11-libraries.html

http://www.eteks.com/pja/en/

http://www.idautomation.com/kb/xwindow-error.html

Unfortunately, I know X is working okay, but I think it’s configured such that my JVM can’t connect to it. I suspect the answer is in the output of the ps command.

root 6873 5967 0 03:53 ? 00:00:11 /usr/X11R6/bin/X -br -nolisten tcp :0 vt7 -auth /var/lib/xdm/authdir/authfiles/A:0-bI32tt

I think that “-nolisten tcp” flag is messing me up. So I’m sure it’s a config issue, but I don’t know enough about how X works & how java connects to it to be sure.

Any further ideas? Like I said . . . KDE works just fine on this box.

You should be running in headless mode as you don’t really need an x server (I assume).
Try using -Djava.awt.headless=true .

See http://java.sun.com/j2se/1.4.2/docs/guide/awt/AWTChanges.html#headless
for more info.

Thanks,
Dmitri
Java2D Team

Well, two problems with that . . .

  1. I’ve set the java.awt.headless flag in my tomcat startup, and it has no effect at all. It dies every time I try to create a BufferedImage (or any other type of image, for that matter) regardless of what flags I set. Nobody’s tips on how to get tomcat to run headless have ever worked for me with this app. I suspect some of the calls I’m making can’t be done headless. Maybe that’s not right, but SOMETHING’S keeping me from being able to run headless.

  2. I’ve already got X installed. Might as well take advantage of it, right?

Besides, I’ve tracked it down to an xauth issue. Not sure if anybody here is well versed in that or not. Kinda doubt it, since the standard answer around here seems to be “Just run headless”. Which would make sense if I could.

Anyway, if anybody knows xauth and wants to help me troubleshoot this, post a reply, and I"ll give you the specifics of what I’ve done so far, but otherwise, I’ll keep my Xserver stuff out of the Java forums. :slight_smile:

Thanks anyway, though. I appreciate the efforts.