Create Image on Unix

T

Toralf Kirsten

Hi,
I'd like to create an image on a Unix server and save it to file.
This file then should be loaded within a Html file generated by a Java
Servlet using the Tomcat server.
For this purpose I use the classes

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
....
Buffered img = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = img.createGraphics();

But on the Unix system I got the following error:
Screen:
-------
java.lang.NoClassDefFoundError
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Class.java:140)
java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62)
java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1041)
...

Catalina.log:
-------------
Xlib: connection to ":0.0" refused by server
Xlib: No protocol specified

My question is, where can/should I set the DISPLAY variable, e.g. in the
Unix, Tomcat or Java environment?

Any suggestions are welcome. Thanks, Toralf
 
O

Oscar kind

Toralf Kirsten said:
I'd like to create an image on a Unix server and save it to file.
This file then should be loaded within a Html file generated by a Java
Servlet using the Tomcat server.

Why not create a servlet that writes image to the client directly?
You can map the image URL to the servlet, and in the servlet:
1. Set the content type to something like "image/png"
2. Create a byte[] with the image,
3. Set the content length to length of the byte array
4. Write the byte array to response.getOutputStream()

(if the byte[] should become very large, skip steps 2 and 3 and write
directly to the stream)


[...]
Catalina.log:
-------------
Xlib: connection to ":0.0" refused by server
Xlib: No protocol specified

My question is, where can/should I set the DISPLAY variable, e.g. in the
Unix, Tomcat or Java environment?

Personally, I start the JVM for tomcat with the option
"-Djava.awt.headless=true". This ensures that the JVM will not try to
contact the X server.


kind regards,
Oscar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top