You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Mike Curwen <gb...@gb-im.com> on 2003/06/27 16:31:01 UTC

Tomcat Classloaders and loading properties files

Hello,

So I'm writing a few library classes that I hope I'll be able to use
over and over again. Because goodness knows, someone needs to invent the
wheel again. ;)
 
Anyways.. I want my classes to use properties files for configuration,
and what I really want is something like:

1. Place the library.jar file in WEB-INF/lib
2. The classes will load the default properties file (included with the
jar) but if you want to override the values, you can provide your own
properties file in WEB-INF/classes
 
I'm expecting that when I go to load the properties, it will look in
WEB-INF/classes *first*, from this snip from the CLASSLOADER doc
====================================================================
Therefore, from the perspective of a web application, class or resource
loading looks in the following repositories, in this order:

/WEB-INF/classes of your web application 
/WEB-INF/lib/*.jar of your web application 
====================================================================

Ok so far?

So now.. the *code* to make that work?

getClass().getClassLoader().getResourceAsStream(property.filename.starti
ng.with.slash)
 
I've been using just getClass().getResourceAsStream(), but I think to
get the Tomcat-guaranteed behaviour, I need to use the classloader.
And I'm thinking this will still work for non web-app uses of
library.jar
 
Does all that seem accurate? I'm just thinking out loud. ;)

-------------------------------------------
Mike Curwen                   
Intermediate Programmer       www.gb-im.com
-------------------------------------------
  ____   ____            ___   __  __ 
 / ___| | __ )          |_ _| |  \/  |
| |  _  |  _ \   _____   | |  | |\/| |
| |_| | | |_) | |_____|  | |  | |  | |
 \____| |____/          |___| |_|  |_|


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