views:

362

answers:

1

Hi all,

in my file "struts-config.xml" I've wrote:

When my application start load successfully application.properties.

How I can reload this properties (because I wanna change a lot of property wrote inside file) without restart application?

Thanks a lot.

T.

+1  A: 

Use (from http://www.docjar.com/html/api/com/opensymphony/xwork2/util/LocalizedTextUtil.java.html):

...
clearMap(ResourceBundle.class, null, "cacheList");

// if it's Tomcat
if ("org.apache.catalina.loader.WebappClassLoader".equals(cl.getName())) {
    clearMap(cl, loader, "resourceEntries");
}
...

private static void clearMap(Class cl, Object obj, String name)
        throws NoSuchFieldException, IllegalAccessException, 
        NoSuchMethodException, InvocationTargetException {
    Field field = cl.getDeclaredField(name);
    field.setAccessible(true);

    Object cache = field.get(obj);

    synchronized (cache) {
        Class ccl = cache.getClass();
        Method clearMethod = ccl.getMethod("clear");
        clearMethod.invoke(cache);
    }
}

Obviously, you can just import that library and use it if you want too.

stevedbrown