Robbie Baldock wrote:
>
> I'm still trying to get Java2D to work on Linux. My latest strategy is
> to run my GIF generation program as a servlet.
>
> What I'm doing is firing up Xvfb to simulate an X environment but then
> of course I need to set the DISPLAY environment variable for the servlet
> and I'm unclear as to how I should do this.
>
> At the moment I'm calling this in my servlet's init():
>
> Runtime.getRuntime().exec("DISPLAY=localhost:1.1");
> Runtime.getRuntime().exec("export DISPLAY");
>
> Which I suspect is the wrong way to do it as this should be done before
> the servlet starts. So the question is, how do I set this environment
> variable just for the servlet?
No, this won't work. What it's doing is starting up a subshell, setting
the environment in that subshell, and then that subshell is going away
without doing any real work. In fact, these two calls are starting up
(and then not really using) two different subshells.
Environment variables are associated with Unix processes and passed to
child processes. You can't really set one "just for the servlet", you
need to set it for the Unix process under which the servlet is running -
meaning the JVM. Unfortunately, Java doesn't let you get to the Unix
environment variables without writing your own native code (platform
independence and such rot), so you have to do it in the environment from
which the JVM is launched. The details depend on how it's launched: if
from a shell script, you can set the environment in the shell script
(DISPLAY=, etc.); if from a C/C++ program, you can call setenv() from
the program... or change the environment from which *that* program is
launched. I hope this makes some sense... it should once you've made
sense of the relationship between Unix processes and environment.
Down in the bowels of X clients, it's possible to open any display you
want to, not necessarily the one specified in the environment. Maybe
there's some method to pass this request to Java for which I haven't
found any documentation.
> I don't know if this is related but the servlet is generating an error
> message in the JServ logs:
>
> java.lang.NoClassDefFoundError: sun/awt/X11GraphicsEnvironment
> at java.lang.Class.forName0(Native Method)
> at java.lang.Class.forName(Class.java:124)
> at
> java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:63)
> at java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1009)
>
> Which is giving me concern as it doesn't seem to have anything to do
> with my attempts to set the DISPLAY variable...
You're right, that's not the message you'd see with an unset DISPLAY
variable. That class should be in rt.jar... I wonder why you're not
finding it.
Nathan
----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]