Craig -
I think I found a way to make it work ---
InputStream stream =
Thread.currentThread().getContextClassLoader().getResourceAsStream("myApp.pr
operties");
That loaded my file from %TOMCAT_HOME%/lib directory. Should I be concerned
about portability? Will this work in the Tomcat 4.0 world?
thanx,
JP
----- Original Message -----
From: "Craig R. McClanahan" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, March 31, 2001 8:59 PM
Subject: Re: getResourceAsStream - properties files
>
>
> On Sat, 31 Mar 2001, Java Poop wrote:
>
> > Hey guys-
> >
> > I'm trying to figure out way to separate my initialization parameters
> > from my application.war file. Because certain things are different
> > between dev, qa and live machines (such as database hostname,
> > username, password, etcs), I rather not put these values in the
> > web.xml file. (The web.xml would be stuck in the application.war file
> > and I don't want the deployment people to unjar it in a deployment
> > setting to change the values of web.xml).
> >
> > So, I'm looking at trying to setup my own properties file that a
> > singleton class would read in my web application and set as global
> > variables for all my servlets/jsps. However, I'm having trouble
> > writing the code to open up the properties file. I'd like to put the
> > properties file in %TOMCAT_HOME%/settings directory (I made this
> > directory up and added it to the classpath in my tomcat.bat file).
> >
> > >From some previous posts on this list, I'm trying :
> >
> > InputStream stream =
> > this.getClass().getResourceAsStream("testApp.properties");
> >
>
> This is supposed to work if you store the testApp.properties file in
> WEB-INF/classes, *and* your servlet class itself was loaded from either
> WEB-INF/classes or WEB-INF/lib.
>
> > But it fails. If I use a File stream and point right at the file, it
> > does load. Just as a test, I tried copying this file to the same
> > location where the class was, as well as myapplication/WEB-INF/classes
> > and myapplication/WEB-INF/lib, and still could not get the file
> > loaded.
> >
> > What would be the proper way to have this loaded (preferably in the
> > settings directory since I can't rely on my war file being unjar'd by
> > future tomcats).
> >
> > BTW- I'm using Tomcat 3.2.1 in Standalone, Win2K, JDK1.3.
> >
> > Thanks in advance, JP
> >
>
> What I do for things like this is to put configuration files like this in
> the WEB-INF directory of my webapp. Then, I can call:
>
> InputStream is =
>
getServletContext().getResourceAsStream("/WEB-INF/testApp.properties");
>
> which will work when the WAR is either packed or unpacked.
>
> Craig McClanahan
>
>
>