You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by es...@eas.san-jose.ca.us on 2001/04/17 22:27:27 UTC

How to read property files?

I would like to put a myapp.properties file in the top level directory
of my webapp. But I can't figure out what filepath to give the
Properties.load() method in order to load my servlet property object.
Can someone help me?

Thanks

=eas=


Re: How to read property files?

Posted by Sam Newman <sa...@stamplets.com>.
Could you get the resource URL of the class loading the properties file, and
then strip off the package and class name? e.g. if Im loading bob.properties
from class Bob in package com/fred/, my resource url for the class would be
/usr/tomcat/webapps/mycontext/WEB-INF/classes/com/fred/Bob.class. If I strip
off the package names and the Bob.class I'd get the path to a props file in
the root. You'll have to play around with this if the class is in a jar
file. Likewise, when loading the props file using the string name, remember
to use File.seperator rather than hardcoding a forward slash.

sam
----- Original Message -----
From: <es...@eas.san-jose.ca.us>
To: <to...@jakarta.apache.org>
Sent: Tuesday, April 17, 2001 9:27 PM
Subject: How to read property files?


> I would like to put a myapp.properties file in the top level directory
> of my webapp. But I can't figure out what filepath to give the
> Properties.load() method in order to load my servlet property object.
> Can someone help me?
>
> Thanks
>
> =eas=
>