tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Roberto Bouza <rbo...@efcholdings.com>
Subject Re: Loading Properties Files
Date Wed, 04 Dec 2002 22:49:01 GMT

 Thats right.

 If you don't have a .war file, you can use the classes dir inside your WEB-INF
dir, and create a new directory like "conf", the put inside all the properties
files. In that way the ClassLoader looks for  the files in there when you use
something like this:

 	try {
	    Properties props = new Properties();
	    InputStream in = getClass().getResourceAsStream("/conf/db.properties");
	    props.load(in);
        ......
  
             propertie1 = props.getProperty("propertie1");

 C'ya

Quoting Will Hartung <willh@msoft.com>:

> > From: <echambe1@TXU.COM>
> > Subject: Loading Properties Files
> 
> 
> > My problem is that the class cannot location my properties file. I am
> > unable to
> > use other suggested methods that I have noticed on this list since those
> > problems
> > involved Properties File within Servlets.
> >
> > After some testing, I determined for some reason the default directory it
> > is looking
> > for my properties file is the Windows System Directory (Determined this
> by
> > opening
> > a file in the default directory, outputing something in it and searching
> > for the file).
> >
> > Anyone have any ideas on how to solve this problem? I do not want to hard
> > code the
> > exact location due to obvious reasons
> 
> The problem is that you appear to be loading a file with an absolute path,
> versus the common form of load a properties file via the ClassLoader.
> 
> Fumble about with the ClassLoader.getResourceAsStream to have it hunt down
> your properties file, and then feed that stream to your Properties.
> 
> public static yourMethod()
> {
>     ClassLoader cl = YourClass.class.getClassLoader();
>     Properties prop = new Properties();
>     prop.load(cl.getResourceAsStream("yours.properties"));
> }
> 
> Then, just drop your properties at the right place in your WARs classes
> area.
> 
> Regards,
> 
> Will Hartung
> (willh@msoft.com)
> 
> 
> 
> 
> --
> To unsubscribe, e-mail:  
> <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:tomcat-user-help@jakarta.apache.org>
> 
> 


-- 
=             Roberto Bouza Fraga               =
===================================
      Research & Development Engineer
       Ella Cisneros Fontanals Holdings
 Ph: (305)-860-0116 / Fax:(305)-860-9401
===================================
       e-Mail:rbouza@efcholdings.com

--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message