We are developing a web application in Eclipse which works fine for me as I deploy it with the Java EE Preview server, my colleague however gets a MissingResourceException for the internationalization file "messages.properties" even though Tomcat successfully deploys the resource file to WEB-INF/classes.
private static final ResourceBundle RESOURCE_BUNDLE = resourceBundle.getBundle("mypackage.messages");
The package structure is like:
mypackage/Messages.java (.class in Tomcat .../WEB-INF/classes)
mypackage/messages.properties
mypackage/messages_de_DE.properties
Because the class loader successfully loads the Messages class I don't understand why it doesn't find messages.properties file even though it resides in exactly the same directory. We both have german locale.
What can I do here? The error:
java.util.MissingResourceException: Can't find bundle for base name messagebundle, locale de_DE
java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1499)
java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1322)
java.util.ResourceBundle.getBundle(ResourceBundle.java:724)
de.uni_leipzig.simba.saim.SAIMApplication.<clinit>(SAIMApplication.java:29)
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
java.lang.reflect.Constructor.newInstance(Constructor.java:525)
java.lang.Class.newInstance0(Class.java:372)
java.lang.Class.newInstance(Class.java:325)
com.vaadin.terminal.gwt.server.ApplicationServlet.getNewApplication(ApplicationServlet.java:82)
com.vaadin.terminal.gwt.server.AbstractApplicationServlet.createApplication(AbstractApplicationServlet.java:978)
com.vaadin.terminal.gwt.server.AbstractApplicationServlet.findApplicationInstance(AbstractApplicationServlet.java:801)
com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:456)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
OK, I have resolved the issue by following the stackoverflow thread MissingResourceException due to class loader constallation (caller not in WEB-INF/classes)
What fixed it was
ClassLoader cl = Thread.currentThread().getContextClassLoader();
ResourceBundle rb = ResourceBundle.getBundle(textproperties, locale, cl);