• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

defining/exporting environement variables from tomcat server

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Saloon Keeper
Posts: 23274
158
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Karl Krasnowsky
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 23274
158
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Look ma! I'm selling my stuff!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic