| ||||||||||||
A repository of notes and comments that will eventually make their way into the documentation. Please treat the information here with caution, it has often not been verified. How can I load configuration files for a class that might be used outside of a web-app?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? You can use 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 or in the directory, or even in a jar file in .The basic call would be:
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:
|