i need to access a configuration file with some properties from a class inside a webapp.
The webapp consist of a servlet that uses another class.
In that class i want to access a configuration file.
Which is the best way?
i need to access a configuration file with some properties from a class inside a webapp.
The webapp consist of a servlet that uses another class.
In that class i want to access a configuration file.
Which is the best way?
you can put a properties file under your WEB-INF/classes directory. in that way it wil be visible on the classpath, then in your java class you can use :
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("your_file.properties");
public void setProperties(Properties props) method, wich lets me use the component in many different environments, for instance: in a JUnit test (I don't have to bother about external files, just create new Properties() on the fly), or in a Spring context (I can easily inject values in a XML beans file). Furthermore I can easily swap from one config file name to another, or even change file format, without affecting my component.