Read about using properties files. They're typically called <name>.properties.

Snippet of code that can be placed in a ServletContextListener.

String resource = "some.properties";
InputStream in = this.getClass().getClassLoader().getResourceAsStream(resource);
try {
     props.load(in);
     in.close();
    } 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 
information.

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 some.properties 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 
package.

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

. . . . just my two cents.

/mde/

----- Original Message ----
From: srd.pl <srolek2...@yahoo.com>
To: users@tomcat.apache.org
Sent: Sat, December 4, 2010 3:58:25 AM
Subject: Place .ini conf file inside the war package.


Hello,

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: 
http://old.nabble.com/Place-.ini-conf-file-inside-the-war-package.-tp30366628p30366628.html

Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org


      

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to