tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Re: Place .ini conf file inside the war package.
Date Sun, 05 Dec 2010 19:19:32 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Pid,

On 12/4/2010 5:07 PM, Pid wrote:
> 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()

It's probably better to use ServletContext.getResource() (returns a URL)
because then you might be able check it's last modified date.

I haven't tried it, but a JarURLConnection might be nice enough to
properly implement the getLastModifiedDate method.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkz75cMACgkQ9CaO5/Lv0PDfcgCeL1INqRVJTR/DrfqtbT4pJfXL
VQUAoJ1PXqDjDpVL8NiTz+079TeoNtL3
=f5Cd
-----END PGP SIGNATURE-----

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


Mime
View raw message