On Mon, 8 Apr 2002, Bryan P. Glennon wrote:
> Date: Mon, 8 Apr 2002 17:24:19 -0500
> From: Bryan P. Glennon <[EMAIL PROTECTED]>
> Reply-To: Tomcat Users List <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> Subject: War files and config info
>
> Hi -
> We have a web app that gets distributed in a war file to a tomcat
> 4.0x server. One of the things in the war file is a configuration file
> for the app. This is an XML file that we open as a resource (using
> getResourceAsStream()) in our main servlet init() method. So far, so
> good. But, we need a way to override this file so that we can make
> config changes without redistributing the entire application. If we
> don't use a war file, we can just put the override file (using the same
> name) in a directory that is earlier in the class path. But we would
> like to keep the war file, since it does make distribution a bit easier.
>
> Any ideas on how to make this work?
>
> FYI, the exact call we use to open the config file is InputStream
> in = this.getClass().getClassLoader().getResourceAsStream(configFile);
One approach to "customizing configuration without messing with the WAR
file" is to use "environment entry" elements instead. Unlike some
suggestions, this one is portable to all J2EE servers, Tomcat 4, and
probably other servlet containers as well.
The basic idea is that you declare your configuration parameters as
<env-entry> references (with default values) in the web.xml file. For
example, in a Payroll webapp you might have:
<env-entry>
<env-entry-name>maxExemptions</env-entry-name>
<env-entry-value>15</env-entry-value>
<env-entry-type>java.lang.Integer</env-entry-type>
</env-entry>
In your servlet (or in a JSP or JavaBean referenced by that servlet), you
can retrieve this value as follows:
InitialContext ic = new InitialContext();
Integer value = (Integer) ic.lookup("java:comp/env/maxExemptions");
int maxExemptions = value.intValue();
The reason to go through all of this, though, is that you can override the
default value in the server configuration -- for Tomcat 4, you do that in
the server.xml file:
<Context path="/myapp" ...>
...
<Environment name="maxExemptions" value="20"
type="java.lang.Integer"/>
...
</Context>
You can define <env-entry> elements of any of the standard Java primitive
types (by using the corresponding wrapper class) or String. If there are
more variables than you really want to configure this way, one option
would be to create a single String-valued environment entry that is simply
the absolute pathname to a properties file somewhere on the host server.
>
> TIA,
> Bryan
>
Craig
--
To unsubscribe: <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>