| Author |
defining/exporting environement variables from tomcat server
|
Karl Krasnowsky
Ranch Hand
Joined: Jan 16, 2009
Posts: 97
|
|
Tomcat 6
While I can find reams of information on setting up an OS environment for running tomcat, I'd like to define a variable within tomcat so that when my jsp's and supporting bean code run they can utilize these variables at server runtime.
Hoping this is pretty obvious, but where/how are such variables defined within the Tomcat configuration system?
In JBoss I can do this by defining such properties in the deploy/properties-service.xml
Is there a like process for doing this in vanilla Tomcat?
thanks,
Karl
|
[SCJP 6]
[SCBCD in process]
|
 |
Tim Holloway
Saloon Keeper
Joined: Jun 25, 2001
Posts: 14475
|
|
|
I'm not sure I understood that, but if you're saying what I'm thinking you're saying, you can define a resource property and use JNDI code in the app to get its value. Simple property values can be read directly that way. If you have lots of properties, setup a simple property that locates the property set. Something like the absolute path of an externally-supplied properties file or a jdbc URL.
|
Customer surveys are for companies who didn't pay proper attention to begin with.
|
 |
Karl Krasnowsky
Ranch Hand
Joined: Jan 16, 2009
Posts: 97
|
|
Tim Holloway wrote:I'm not sure I understood that, but if you're saying what I'm thinking you're saying, you can define a resource property and use JNDI code in the app to get its value. Simple property values can be read directly that way. If you have lots of properties, setup a simple property that locates the property set. Something like the absolute path of an externally-supplied properties file or a jdbc URL.
Well, I need something even more basic.
In JBoss you can simply do something like this:
and (I assume) on jvm startup of the server it simply appends this to the property set so in your code you can do this:
and there you go... no special context mapping, just a basic property call.
|
 |
Tim Holloway
Saloon Keeper
Joined: Jun 25, 2001
Posts: 14475
|
|
You should be able to do that in Tomcat by creating a "setenv.bat" or "setenv.sh" file (depending on OS) in TOMCAT_HOME/bin. Put this line in it:
Caution: because this is a System property, it will apply to ALL java code in the Tomcat JVM. Sometimes per-application properties are preferable. Also, since it's outside of the direct scope of J2EE, there can be maintenance issues involved, since most of us don't think of externally-imposed properties as part of the webapp and therefore don't go looking for them when we deploy to a new server or something like that.
Actually, I've never used a simple property setting in JBoss, and I'm not sure what caveats are attached to it. As I said, it's not standard J2EE usage.
|
 |
 |
|
|
subject: defining/exporting environement variables from tomcat server
|
|
|