<document>
<description> I have a class needs to load a configuration file. This class is independent of the ServletApplication, it could be deployed in a web application or someplace else. What is the best way to allow my class to access the configuration file? </description>

You can use ClassLoader to load your configration file from anywhere in the classpath.

A file from the classpath is always available to every class using the ClassLoader.getResourceAsStream method. So you don't need to pass around any servlet context information.

The classpath also gives you a good deal of options of how to package your files. You can put them in jars in WEB-INF/lib or in the WEB-INF/classes directory, or even in a jar file in $RESIN_HOME/lib.

The basic call would be:

<example> ClassLoader loader = Thread.currentThread().getContextClassLoader(); InputStream is = loader.getResourceAsStream("config/myconfig.xml"); </example>

The classpath is used to find the file, and the first one found is used. An example of the search order for the above example is:

1. $RESIN_HOME/lib/anyjar.jar!/config/myconfig.xml
2. WEB-INF/classes/config/myconfig.xml
3. WEB-INF/lib/anyjar.jar!/config/myconfig.xml

</document>