Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes EJB and other Java EE Technologies and the fly likes Volatile property files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Volatile property files" Watch "Volatile property files" New topic

Volatile property files

Graham Mead
Ranch Hand

Joined: Sep 28, 2001
Posts: 57
We have a J2EE application which contains a property file for MQ settings that we need change on a frequent basis. This is currently only referenced from code in the WAR file.
Initially we put this in a jar in the EAR referenced by the WAR manifest, because later modules may need access to it. However being in a jar this makes it a pain to update.

Where is the recommended J2EE place within the WAR,EAR or elsewhere so that a) the code can find it, we are using this.getClass().getClassLoader().getResourceAsStream() to load it. and b) we can gain access to it easily to modify the contents?
Thanks for any help
Greg Charles

Joined: Oct 01, 2001
Posts: 2967

I've run up against this problem several times, but I don't have a great solution. As far as I can tell, it's impossible to update a properties file in a jar. The best bet is to put it on the file system, possibly at a location defined by a system property. I usually use WebLogic, so I set this system property using a -D option in the startWebLogic script.
BTW, this.getClass().getResourceAsStream(String) should work for reading. Why do you need to retrieve the class loader?
Graham Mead
Ranch Hand

Joined: Sep 28, 2001
Posts: 57
Hi thanks for the reply
We use the getClassLoader method first to ensure that we are attaining the right level of module visibility within J2EE.
This was after discussing visibility problems with IBM and it is also referred to in Tim Deboers article and on other websites I've seen concerning the same problems.
He says
"A common portable technique for finding resources (property files, images, and so on) is to use the classloader's findResourceXX methods. Based on the previous discussion, you can see why it is important to use the right classloader for this job. For example, if you use the WebSphere classloader, you won't be able to find any resources in your modules"
Graham Mead
Ranch Hand

Joined: Sep 28, 2001
Posts: 57
Apologies that should be
I agree. Here's the link:
subject: Volatile property files
It's not a secret anymore!