tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ralph Einfeldt" <ralph.einfe...@uptime-isc.de>
Subject AW: Reading properties file from ClassPath (ServletContextListener)
Date Thu, 01 Aug 2002 14:27:02 GMT
What do you mean with 'classpath'?

Tomcat ignores the classpath environment variable.
So your property file has to reside in a directory 
that is known to tomcat.
Even using the SystemClassLoader (which is done when 
you use getSystemResource()) won't help because the 
classpath is cleared in the startsrcipt of tomcat.

So the file has to one of these:
    * webapps/{Context}/WEB-INF/classes/com/foo/My.properties
    * $CATALINA_BASE/common/classes/com/foo/My.properties
    * $CATALINA_BASE/classes/com/foo/My.properties

To read more about this:
http://jakarta.apache.org/tomcat/tomcat-4.0-doc/class-loader-howto.html

BTW: Is there any reason why you use getSystemResource()
instead of getSystemResourceAsStream() ?

Ralph Einfeldt
Uptime Internet Solution Center GmbH
Hamburg, Germany
Hosting, Content Management, Java Consulting
http://www.uptime-isc.de 

> -----Urspr√ľngliche Nachricht-----
> Von: petra staub [mailto:calc42@hotmail.com]
> Gesendet: Donnerstag, 1. August 2002 16:05
> An: tomcat-user@jakarta.apache.org
> Betreff: Reading properties file from ClassPath 
> (ServletContextListener)
> 
> I have a registered class as a ServletContextListener.
> At application start I want to read a Properties file
> from the classpath, doing the following:
> 
> myProps = new Properties();
> try {
>    URL url = ClassLoader.getSystemResource("com/foo/My.properties");
>    InputStream istream = url.openStream();
>    myProps.load(istream);
> } catch (Exception exp) {
> 
> }
> 
>

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