Web Servers on Unix and Linux - Tomcat Environment Variables

This is Interesting: Free IT Magazines  
Home > Archive > Web Servers on Unix and Linux > May 2004 > Tomcat Environment Variables





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Tomcat Environment Variables
chakram88

2004-05-18, 5:05 pm

We're running Apache Tomcat 4.1.24.

In an application web.xml file we want to substitute a Linux
environment variable.

Our situation is that we have a total of four different
"environments". Local development (desktop) and three web servers
(test, evaluation and production).

The web.xml has a <context-param> set which is a file path. We'd like
to include a variable in that path, so that the web.xml file could
remain the same in each environment, and tomcat would substitute the
appropriate "realm".

web.xml includes this element:
<context-param>
<param-name>Location</param-name>
<param-value>/usr/local/fileserver/${ENVIRONMENT}/briefs/</param-value>
</context-param>

we've tried setting a JAVA_OPTS='-DENVIRONMENT=test' in the catalina
shell on the test server in the hopes that tomcat would see the
param-value as
/usr/local/fileserver/test/briefs/

Has anyone tried to do something similar?
Juha Laiho

2004-05-19, 5:50 pm

chakram88@yahoo.com (chakram88) said:
>We're running Apache Tomcat 4.1.24.
>
>In an application web.xml file we want to substitute a Linux
>environment variable.


Env.vars as such are not easy for Java; again a curse of vying platform-
independence: not all platforms have env.vars, so Java does not support
the concept. However, what Java has instead are system properties.

>The web.xml has a <context-param> set which is a file path. We'd like
>to include a variable in that path, so that the web.xml file could
>remain the same in each environment, and tomcat would substitute the
>appropriate "realm".
>
>web.xml includes this element:
> <context-param>
> <param-name>Location</param-name>
> <param-value>/usr/local/fileserver/${ENVIRONMENT}/briefs/</param-value>
> </context-param>


As you need to set context params within the application, I'm not a great
fan of the idea. I more like JNDI or system properties.

For JNDI, see the server.xml that is shipped with Tomcat, and the Jndi.java
within the examples.

>we've tried setting a JAVA_OPTS='-DENVIRONMENT=test' in the catalina
>shell on the test server in the hopes that tomcat would see the
>param-value as
>/usr/local/fileserver/test/briefs/


This is rather close, so here you're setting a system property with name
ENVIRONMENT. However, there is no simple way to get that evaluated from
within the context param, so I guess easier yould be to create the full
location as a system property:
JAVA_OPTS="-Dyourapp.location=/usr/local/fileserver/$ENVIRONMENT/briefs"
and refer to that from within your code. Check the Java core API docs for
more info on system properties.
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)
chakram88

2004-05-20, 5:43 pm

Juha Laiho <Juha.Laiho@iki.fi> wrote in message news:<c8g40j$ji0$1@ichaos.ichaos-int>...

> within the context param, so I guess easier yould be to create the full
> location as a system property:
> JAVA_OPTS="-Dyourapp.location=/usr/local/fileserver/$ENVIRONMENT/briefs"
> and refer to that from within your code. Check the Java core API docs for
> more info on system properties.


Aha -- this is where I was starting to lean.

Thanks for your input, I've obviously got some more reading to do.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com