aspose file tools*
The moose likes Java in General and the fly likes Properties or Resource Bundle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Properties or Resource Bundle" Watch "Properties or Resource Bundle" New topic
Author

Properties or Resource Bundle

Karthik Rajendiran
Ranch Hand

Joined: Aug 13, 2004
Posts: 211
Hello Friends,
I am developing one application, where we need to maintain some application configuration in a properties file. and some messages in another properties file

file1: config.properties
file2: appMesages.properties

This application consists of 2 war[1 webservices, 1 normal web UI] and 1 ear [mdb] going to be deployed in oc4j.

This is a mission criticalapplication, cannot be restarted many times.

q1)
I would like to know what are the ways we can reload a properties file once a change has been done.

q2) Since i have 2 war, 1 ear, where can i keep this resources files and make it use across the application in the domain. is there any way to specify the path

At Present,

I am using ResourceBundle


But if business or my deployer changes the properties file , how to make application recognise it and use it without restarting.

Can anyone help me out?
Regards


SCJP 1.4 SCWCD 1.4 SCDJWS 1.4
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

I imagine this is easiest to achieve using a ResourceBundle.Control subclass that overrides the getTimeToLive method by either returning zero (validate* the resource every time it is retrieved), TTL_NO_CACHE (don't put the bundle in a cache - effectively reload bundle every time the factory method is called), or has some count-down that sets a reasonable amount of time between validations.

*Validate means it will use the needsReload method to check if the data in the ResourceBundle needs to be reloaded. Typically for .properties files that would mean checking if the modified time of the file is after a timestamp the resource bundle holds internally.

For example:


See: ResourceBundle.Control API


Steve
Karthik Rajendiran
Ranch Hand

Joined: Aug 13, 2004
Posts: 211
Thanks steve sir, for the information.
One question.
If we use fileinputstream to load the resources to properties, it would be performance hit rite due to I/O operations. ?
Karthik Rajendiran
Ranch Hand

Joined: Aug 13, 2004
Posts: 211
Regarding the second question,
If i have 2 wars, 1 ear sharing the properties and resources, which is the best way to keep and where to keep in server,

1. inside the jar and give classpath or put it in resources folder of server?
Kuladip Yadav
Ranch Hand

Joined: Jul 30, 2008
Posts: 162

Originally posted by Karthik Rajendiran:
Regarding the second question,
If i have 2 wars, 1 ear sharing the properties and resources, which is the best way to keep and where to keep in server,

1. inside the jar and give classpath or put it in resources folder of server?



put it in resources folder will be good
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Properties or Resource Bundle