I am building a web app based on Maven multi modules. So My project structure is like the following:
/module1
/src/main/java
package/Module1.java
/src/main/resources
conf/i18n_en.properties
/webapp
/src/main/java
package/Web.java
/src/main/resources
conf/i18n_en.properties
/src/main/webapp
I have different properties("i18n_en.properties") for I18N in every module, I load the properties file in code and get the information. It seems good running in single module test.
private ResourceBundle rb;
String filename = BASE_NAME + "_" + LANG + ".properties";
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(filename);
if(in == null) {
in = c.getResourceAsStream(filename);
}
if (in == null) {
in = c.getClassLoader().getResourceAsStream(filename);
}
if (in != null) {
rb = new PropertyResourceBundle(in);
}
However, when I started tomcat with IDEA, the program only load the properties in webapp! Just cannot find the "Module1" s properties!
I think it's the problem of loading properties from innner jar. For the deployed directory is as following:
/WEB-INF
/classes
/conf/i18n_en.properties (from webapp)
/lib
/Module1.jar (has it's own properties in it)
I was really confused. I searched every thing related for a long time and i found some thing similar, but I just can't solve the problem. I think I have done what they said.Java WebApp: Loading resource from .jar located in WEB-INF
I don't know where is the problem, There must be some ways to load the properties inner jar. Anyone knows anything , please help me, thank you very much~