Java 1.6, Struts 2.0.11, Windows OS
我需要在struts.xml
中进行哪些配置才能将基于模块特定标签的属性文件放在src
包文件夹之外?
原因:将所有国际化属性分组在单独的基于模块的文件夹中?
WEB-INF
|_classes
| |__com
| |__xyz
| |__Hellofoo.class
|
|__ struts.xml
|
|__props
|__xyz
|_ en.properties [ English Labels ]
jp.properties [ Japanese Labels]
spn.properties[ Spainish Labels ]
我认为必须在struts。xml文件或属性文件中指定,如
struts.custom.i18n.resources=global-messages, image-messages
或XML文件,如
<constant name="struts.custom.i18n.resources" value="global-messages, image-messages" />
或者你可以使用某种Listener
来定制它根据你的需要。
IMO文本资源应该根据区域和包进行组织,但这是一个选择的问题。
这并不是你具体问题的答案。然而,我认为它可以是有用的人(像我一样)谁偶然发现这个页面的问题"我怎么能设置struts.custom.i18n。资源属性到一个特定的文件夹(在SRC文件夹内,但不是在它的正下方)
现在,当我在struts中设置以下内容时。属性,它不起作用
struts.custom.i18n.resources=resources/locale-bundles/label-values,resources/locale-bundles/error-values
但是,如果我在struts.xml中设置它,它会。(不知道为什么)
<constant name="struts.custom.i18n.resources"
value="resources/locale-bundles/label-values, resources/locale-bundles/error-values" />
我找到了一个解决方案
在struts.properties
struts.custom.i18n.resources=globalMessages
中居首然后,将下面的代码添加到您的StartupServlet或其他将在服务器启动的地方执行的地方
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();
}