Reputation: 21
Is there any mechanism to load the properties file from the file system in struts2
? I am coming up with a hot deployment mechanism. If I update the war file, it would be redeployed. I am able to reload properties file on the fly using
LocalizedTextUtil.clearDefaultResourceBundles();
LocalizedTextUtil.addDefaultResourceBundle("struts/resources");
but it would only look in the struts2
default location.
Any solution, hack, workaround is heartily welcomed.
Upvotes: 2
Views: 2676
Reputation: 65
I found a solution
first in struts.properties struts.custom.i18n.resources=globalMessages
then, add the below code to the your StartupServlet or some other place that will execute where the server start
URL[] urls;
try {
File file = new File("/your path");
URL url = file.toURI().toURL();
urls = new URL[]{url};
ClassLoader cl = new URLClassLoader(urls);
LocalizedTextUtil.setDelegatedClassLoader(cl);
LocalizedTextUtil.addDefaultResourceBundle("globalMessages");
} catch (MalformedURLException e) {
e.printStackTrace();
}
Upvotes: 2
Reputation: 1729
You can achieve this by: 1. Tell struts to use a certain property bundle. 2. Add it to the classpath
Example:
In Struts.properties:
....
struts.custom.i18n.resources=globalMessages
....
Create globalMessages.properties
(and any locale specific bundles, such as globalMessages_ru_RU.properties
), place the bundle(s) in a folder called /app_conf/i18n
and finally place the directory /app_conf/i18n
in the class path.
Upvotes: 0