On 12/4/10 5:41 PM, Mark Eggers wrote:
> 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: ServletContext.getResourceAsStream()

Note: once loaded you'll have to organise reloading yourself - the
properties don't update just because you change the file on disk.


p

> 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. 
> 
> 

Attachment: 0x62590808.asc
Description: application/pgp-keys

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to