0 Replies Latest reply on Aug 27, 2009 8:43 AM by Dieter Rehbein

    clear resource bundle cache, a solution (requires Java 6)

    Dieter Rehbein Newbie

      Hi all,

      during development I don't want to restart the applicaction server just because a message has been added or modified. Since the resource bundles are cached, a method to clear that cache is required.

      I've implemented a simple seam component, which can be used to clear the cache. Maybe this helps some other people using SEAM:

      public class ClearResourcesAction extends SkilineAction
         private static final long serialVersionUID = 6353316361885036069L;
         public static final String COMPONENT_NAME = "clearResourcesAction";
         private ResourceBundle resourceBundle;
         public void clearResources()
               SeamResourceBundle seamResourceBundle = (SeamResourceBundle)resourceBundle;
               Field field = seamResourceBundle.getClass().getDeclaredField("bundleCache");
               Map bundleCache = (Map)field.get(resourceBundle);
               statusMessages.add("Resourcebundle cache cleared");
            catch(Exception e)
               statusMessages.add(Severity.ERROR, "Could not clear resource bundle cache: {0}", e);

      The class SeamComponents defines constants for some built in seam components. SeamComponents.RESOURCE_BUNDLE is defined as org.jboss.seam.core.resourceBundle.

      The static method java.util.ResourceBundle.clearCache was introduced in Java 6, so this solution doesn't work with Java 5!