Yes Donie, but this won't work if the webapp is deployed as a war without expansion.
Andreas On 8 Oct 2002 at 17:06, Donie Kelly wrote: > Here is the simple solution > > ServletContext sc; > String RootPath=null; > > sc = getServletContext(); > RootPath = sc.getRealPath("/"); > > Donie > > -----Original Message----- > From: Andreas Probst [mailto:[EMAIL PROTECTED]] > Sent: 08 October 2002 16:31 > To: Tomcat Users List > Subject: Re: How to specify the location of a properties file. > > Hi Mehdi, > > you could get the resource stream from within a servlet's init() > method (where you have a ServletContext) and pass it to the > other object that needs it. > > I do it pretty similar. But instead of passing the stream I pass > the servletContext. > > Andreas > > > On 8 Oct 2002 at 15:40, [EMAIL PROTECTED] wrote: > > > > > Hi, > > > > There was no ServletContext.getResourceAsStream () ... maybe this is > > because the whole project is a bunch of utilities for my web-app, and is > > not a webapp itself ? The class that needs the properties file, is not > part > > of the webapp. So anyway, i tried the closest available method.. (or so i > > thought); > > > > p.load( javax.servlet.ServletContext.class.getResourceAsStream( > > "/WEB-INF/myprops.properties") ); > > > > which also did not work. > > > > Cheers, > > > > Mehdi > > > > Mehdi Nejad - Senior Developer > > [EMAIL PROTECTED] > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > Bluewave Ltd - Online Creations > > http://www.bluewave.com > > Tel. +44 (0)20 7479 8394 > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > > > > > > > "Andreas Probst" > > > <[EMAIL PROTECTED] To: "Tomcat Users > List" <[EMAIL PROTECTED]> > > > cc: > > > Subject: Re: How to > specify the location of a properties file. > > 08/10/2002 13:57 > > > Please respond to > > > "Tomcat Users > > > List" > > > > > > > > > > > > > > > > > Hi Mehdi, > > > > I have my properties file in /WEB-INF. Eclipse doesn't delete it > > there. I access it with > > > > InputStream propsIn = servletContext.getResourceAsStream("/WEB- > > INF/dms.properties"); > > props.load(propsIn); > > > > As far as I know this also works when the web-app ist deployed > > as a war without expansion. > > > > Hope that helps. > > > > Andreas > > > > > > > > On 8 Oct 2002 at 12:48, [EMAIL PROTECTED] wrote: > > > > > > > > I use the getResourceAsStram() method also, but i find that my IDE, > tends > > > to remove the properties file from my classpath, as soon as I do a > build, > > > which is not nice. > > > > > > In the particular case i have now, I don't want to specify the > parameters > > > in my web.xml, because the utility that requires a properties file, is > > not > > > actually a web-app, rather a bunch of utility classes used by my webapp. > > > Im not keen to implement a "setProperties()" method, as this would mean > > > changing stuff, so im just re-copying the properties into my classes > > folder > > > after each build.. (unless someone can tell me how to tell WSAD to stop > > > deleting my properties file... but .. *ahem* thats not a Tomcat question > > :) > > > > > > Cheers, > > > > > > Mehdi > > > > > > > > > > > > > > > > > > > > Justin Ruthenbeck > > > > > <justinr@nextengi To: "Tomcat Users > > List" <[EMAIL PROTECTED]> > > > ne.com> cc: > > > > > Subject: Re: How to > > specify the location of a properties file. > > > 07/10/2002 22:20 > > > > > Please respond to > > > > > "Tomcat Users > > > > > List" > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Niaz ... > > > > > > The idea is to load the properties file like you would any other java > > > resource at runtime ... this is (almost) always better, IMHO, than using > > > something J2EE-specific like initialization parameters to a servlet. > > > > > > The relevant code would look something like this: > > > > > > InputStream inStream = this.getClass().getResourceAsStream("/my.props"); > > > Properties props = new Properties(inStream); > > > > > > or > > > > > > Properties prop = new Properties(); > > > prop.load(this.getClass().getResourceAsStream > > ("/MyProperties.properties")); > > > > > > There was a thread some time ago that went over this. You can see the > > > details at: > > > http://www.mail-archive.com/tomcat-user@jakarta.apache.org/msg63518.html > > > > > > Hope this helps... > > > justin > > > > > > > > > At 01:40 PM 10/7/2002, you wrote: > > > >Justin, > > > > > > > >I am facing the same problem. Your approach seems to be an elegent one. > > > >Would you mind eleborating on the idea a little bit more. Some code > > > snippet > > > >would definitely be helpful. > > > > > > > >I thank you in advance. > > > > > > > >niaz. > > > >----- Original Message ----- > > > >From: "Justin Ruthenbeck" <[EMAIL PROTECTED]> > > > >To: "Tomcat Users List" <[EMAIL PROTECTED]> > > > >Sent: Monday, October 07, 2002 4:06 PM > > > >Subject: Re: How to specify the location of a properties file. > > > > > > > > > > > > > > > > > > Shaun -- > > > > > > > > > > Consider dynamically loading the properties file from your classpath > > > using > > > > > a class loader. This way, you can put the files anywhere you please > > > and > > > > > just include that directory in your classpath (or put them someplace > > > > > already in your classpath). If you need more specifics, let me know > > > and > > > > > I'd be happy to help... > > > > > > > > > > justin > > > > > > > > > > At 01:00 PM 10/7/2002, you wrote: > > > > > >I've got a servlet running under Tomcat and I need to read in the > > > >contents > > > > > >of a properties file. There will be different properties files for > > > each > > > > > >system specified using an init parameter. > > > > > > > > > > > >I'm having problems reading this property file at the moment in my > > > java > > > > > >class as the way I am doing it at the moment always looks where I > > > started > > > > > >Tomcat from i.e the /bin directory. I can specify a full path to > > the > > > >file > > > > > >but this is not very system independent and limits me to either > > > Windows > > > >or > > > > > >Unix. > > > > > > > > > > > >What I need is to specify the location of the file relative to the > > > webapp > > > > > >directory. I have tried the url class but it doesn't seem to work, > > or > > > > > >maybe it is working but looking in a different place to where my > > > > > >properties file is. > > > > > > > > > > > >Can anyone suggest what I am doing wrong or provide any help on the > > > use > > > >of > > > > > >urls in Tomcat? > > > > > > > > > > > >Thanks > > > > > > > > > > > > > > > > > >Shaun > > > > > > > > > > > > > > > > > > > > > -- > > > > > To unsubscribe, e-mail: > > > ><mailto:[EMAIL PROTECTED]> > > > > > For additional commands, e-mail: > > > ><mailto:[EMAIL PROTECTED]> > > > > > > > > > > > > > > > > >-- > > > >To unsubscribe, e-mail: < > > > mailto:[EMAIL PROTECTED]> > > > >For additional commands, e-mail: < > > > mailto:[EMAIL PROTECTED]> > > > > > > > > > -- > > > To unsubscribe, e-mail: < > > > mailto:[EMAIL PROTECTED]> > > > For additional commands, e-mail: < > > > mailto:[EMAIL PROTECTED]> > > > > > > > > > > > > > > > > > > > > > -- > > > To unsubscribe, e-mail: < > > mailto:[EMAIL PROTECTED]> > > > For additional commands, e-mail: < > > mailto:[EMAIL PROTECTED]> > > > > > > > > > > > -- > > To unsubscribe, e-mail: < > > mailto:[EMAIL PROTECTED]> > > For additional commands, e-mail: < > > mailto:[EMAIL PROTECTED]> > > > > > > > > > > > > > > -- > > To unsubscribe, e-mail: > <mailto:[EMAIL PROTECTED]> > > For additional commands, e-mail: > <mailto:[EMAIL PROTECTED]> > > > > > > -- > To unsubscribe, e-mail: > <mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: > <mailto:[EMAIL PROTECTED]> > > -- > To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> > -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>