tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Eggers <>
Subject Re: Place .ini conf file inside the war package.
Date Sat, 04 Dec 2010 17:41:50 GMT
Read about using properties files. They're typically called <name>.properties.

Snippet of code that can be placed in a ServletContextListener.

String resource = "";
InputStream in = this.getClass().getClassLoader().getResourceAsStream(resource);
try {
    } catch (IOException ex) {
          ex.printStackTrace(); // ugly

Note that this is not a complete ServletContextListener. Normally I create a 
separate class, have that class's constructor read the properties file, and then 
use the ServletContextListener to create a servlet context attribute with the 

You can use an init parameter to read the resource name from web.xml, and then 
pass that information to your class as an argument to the constructor. Catch 
exceptions (such as file not found) appropriately.

The Apache commons configuration (mentioned in another message) provides a lot 
of nice tools for reading properties files.

Place the file in src/main/resources of your Maven project. This 
will get it packed up in WEB-INF/classes of your war file once you run maven 

Read the javadoc on Class.getResourceAsStream() concerning how to locate the 
properties file.

. . . . just my two cents.


----- Original Message ----
From: <>
Sent: Sat, December 4, 2010 3:58:25 AM
Subject: Place .ini conf file inside the war package.


I have a quick question considering my rest webservice. I would like to
place an .ini file with configuration parameters inside an war file, so that
I can change them wile the app is deployed on tomcat without recompiling.
Can any give an advice on how to do this? And how to open this file (what
path) in my java code. I am using maven so an advice on how to write a
special script in the pom.xml file would be great. 

View this message in context:

Sent from the Tomcat - User mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message