views:

321

answers:

4

What's the best way to pass arguments to a tomcat instance? Are command line arguments available to all applications within the container? Can I pass arguments to particular apps? Do I need to manage this through the built in app server?

EDIT: To clarify, I'm looking to pass a parameter to specify the configs to use. Sometimes this might specify a set of configuration files which can differ per environment.

A: 

Everything can see the generic system environment through the standard Java Properties mechanism. Also, the environment variable CATALINA_OPTS can be used to pass arguments to the JVM.

Will Hartung
I'm not sure if I want to use system variables as I might have other instances of the same app running and want to specify different configs for those.
altCognito
+1  A: 

you can add -Dmy.config.var=configA and -Dmy.config.var=configB and to CATALINA_OPTS (each time the one you need) and read them from java via System.getProperty("my.config.var"). These are not environment variables.

raticulin
I prefer this method wich is relliable for all AS servers (JBOss, etc)
Kamia
A: 

I believe that the best way to configure it would be to use the server.xml and context.xml files. This is the place to add JNDI configuration. You can have a different context.xml file for every application. In your WAR file place this at META-INF directory and Tomcat will import it.

kgiannakakis
A: 

Stuff that needs to go magically to a web application should be put in JNDI. This allows you to put and retreive objects in a "global hashtable" outside somewhere.

If all you need to do is have a configuration file name, then pass in a property (-Dfoo=bar).

Thorbjørn Ravn Andersen