You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Scott Smith <ss...@mainstreamdata.com> on 2008/06/13 09:10:58 UTC

Dynamic ResourceBundle clearCache()

We are trying to build functionality into our website so a website
administrator can update the properties file which contains the webpage
display strings without stopping the website.  He would do this through
an administrative webpage. 

 

The code (excerpted below) works fine when we step through the code when
running Tomcat (5.5, Java 6) under Eclipse.  However, if we put it in a
war file and run it in Tomcat, the clearCache() appears to have no
effect.  We think it should have caused jstl to re-read the properties
file.  We can see that the properties file is getting re-written.
However the string value displayed on the page doesn't change.  If we
restart Tomcat, then the new string value takes effect, but that
obviously doesn't work in the long run.

 

There is a comment that it clears the properties files for any
properties files that have been read in with the current ClassLoader.
But we aren't sure what ClassLoader to specify if it's not the current
one.

 

Does anyone have any idea why this might not work or an alternative
suggestion on how to do what we want to do? 

 

 

        File propertiesFile = new File("myproperty.properties");

  Properties p = new Properties();

        FileReader fr = new FileReader(propertiesFile);

        p.load(fr);

        fr.close();

        p.setProperty("my.key", "the string");

        FileWriter fw = new FileWriter(propertiesFile);

        p.store(fw, "");

        fw.flush();

        fw.close();

        ResourceBundle.clearCache();

        PropertyResourceBundle rb = (PropertyResourceBundle)
ResourceBundle.getBundle("myproperty");

        PropertyResourceBundle.clearCache();

        Config.set(ses.getServletContext(),
Config.FMT_LOCALIZATION_CONTEXT, new LocalizationContext(rb));