War files and config info

2002-04-08 Thread Bryan P. Glennon

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);

TIA,
Bryan

--
To unsubscribe:   
For additional commands: 
Troubles with the list: 




RE: War files and config info

2002-04-08 Thread Jeremy Joslin

Try setting a parameter in your web.xml to the value of an external
location for your config file.  Inside your init() method check this
location first for the config file you want to load, if you find it load
it and move on, else load the config file you distributed with your
application.  Hope this helps.

Jeremy Joslin
Software Engineer
Spotlife Inc.

> -Original Message-
> From: Bryan P. Glennon [mailto:[EMAIL PROTECTED]] 
> Sent: Monday, April 08, 2002 3:24 PM
> 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);
> 
> TIA,
> Bryan
> 
> --
> To unsubscribe:   <mailto:[EMAIL PROTECTED]>
> For additional commands: <mailto:[EMAIL PROTECTED]>
> Troubles with the list: <mailto:[EMAIL PROTECTED]>
> 


--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>




Re: War files and config info

2002-04-08 Thread Craig R. McClanahan



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
 references (with default values) in the web.xml file.  For
example, in a Payroll webapp you might have:

  
maxExemptions
15
java.lang.Integer
  

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:


...

...


You can define  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]>