Ive been trying to make a simple servlet work that generates an image on the fly using BufferedImage. Like a number of posts on this forum, Im having difficulty, always running into a NoClassDefFoundError: sun/awt/X11GraphicsEnvironment error on my headless server, running JDK1.4.2, despite java.awt.headless being set to true.
Looking thorugh the source code in src.zip on my jdk, I came across this in java.awt.GraphicsEnvironment and wonder if anybody else agrees.
try {
localEnv = (GraphicsEnvironment) Class.forName(nm).newInstance();
if (isHeadless()) {
localEnv = new HeadlessGraphicsEnvironment(localEnv);
}
} catch (ClassNotFoundException e) {
throw new Error("Could not find class: "+nm);
} catch (InstantiationException e) {
throw new Error("Could not instantiate Graphics Environment: " + nm);
} catch (IllegalAccessException e) {
throw new Error ("Could not access Graphics Environment: " + nm);
}
Surely, it would be better to check for headless first, and if not, then get the non-headless class? Especialy since this is where it falls over in most peoples code.