Refresh Resource Bundles in WebSphere Commerce

Refresh Resource Bundles in WebSphere Commerce

For those that use WebSphere Commerce, especially if you’re taking advantage of internationalization and localization, you’ve used many a resource bundles. You also understand how challenging it can be when you have to consistently modify your properties, only to have to restart your application server in order to view the updates.

Here is a solution that will allow you to change your property files, and refresh them automatically without restarting your application server. This piece of logic resides in a JSP page, as I can just copy it around to the projects I’m working on.

Here is the JSP code that I leverage in order to refresh my property resource bundles.

<%@ page import="java.util.*, java.lang.reflect.*"%>
<% 
Class klass = Class.forName("java.util.ResourceBundle").getSuperclass();
Field field = klass.getDeclaredField("cacheList");
field.setAccessible(true);
sun.misc.SoftCache cache = (sun.misc.SoftCache)field.get(null);
cache.clear();
field.setAccessible(false);
%>
<body>
<p style="text-align: center;">The Property Resource Bundles were reset on <%=new java.util.Date()%>.</p>
</body>

Author: daharveyjr

I’m a solution architect responsible for the design, development, implementation, testing, and maintenance of e-commerce operations and applications using the Hybris and WebSphere Commerce product suites and other web technologies such as Java, J2EE/JEE, Spring, PHP, WordPress and more. Twitter | Facebook | LinkedIn

2 thoughts on “Refresh Resource Bundles in WebSphere Commerce

  1. Praveen Reply

    Hi
    I was interested in this. Since we have multiple locales, this would help us in avoiding few restarts
    But i am getting error.
    Caused by: java.lang.NoSuchFieldException: cacheList
    at java.lang.Class.getDeclaredFieldImpl(Native Method)

    Did you encounter anything like this.

    regards
    Praveen

  2. rajesh Reply

    hi, I’m also getting the same Error, Would you please elaborate how to do this?

Leave a Reply

Your email address will not be published. Required fields are marked *