0

i'm trying to reload resource bundle during runtime. In my application, after the login, i get the properties calling <f:loadBundle basename="messages" var="msg" />. The call is made in my application base template and all is working well. The property file is located under MyApp/resources/

The next step is trying to update the resourceBundle reading from a property file i have in my userHome/resources. What i'm doing calling my managed bean is:

File file = new File(System.getProperty("user.home")+ "/resources/");
    URL[] urls = {file.toURI().toURL()};
    ClassLoader loader = new URLClassLoader(urls);

    ResourceBundle.clearCache(Thread.currentThread().getContextClassLoader());  
    ResourceBundle.clearCache();
    bundle = ResourceBundle.getBundle("messages",Locale.ENGLISH, loader);

I got no errors and the boundle got the right values BUT any changes took places in my application. Someone can tell me how to reload the bundle and show the new values i got from the external files?? Clear cache doesn't seem to work,i get rid of the faces-config.xml cause of jsf2... Hope someone can help.

aegis80
  • 1
  • 2
  • One thing is to load the bundles programatically. Other thing would be to keep them refreshed when you update them. I suppose you are aiming to the second one? – Aritz Feb 05 '14 at 10:38
  • Yes i would like to refresh them each time i make a change to the properties files i have under user/resources – aegis80 Feb 05 '14 at 13:10

1 Answers1

0

you can use Apache Commons Configuration to resolve this issue,

PropertiesConfiguration propertiesConfig = new PropertiesConfiguration("yourProps.properties");
propertiesConfig.setReloadingStrategy(new FileChangedReloadingStrategy());

For this you need to use commons-configuration dependency / jar.

<dependency>
    <groupId>commons-configuration</groupId>
    <artifactId>commons-configuration</artifactId>
    <version>20041012.002804</version>
</dependency>

you can find further details in the java-doc,

Resource: hot-reload-of-properties-file

Chandra Sekhar
  • 16,256
  • 10
  • 67
  • 90