Technote (troubleshooting)
Problem(Abstract)
In the following scenario, a MissingResourceException is thrown on Java Architecture for XML Binding (JAXB)-related API classes at run time: The application that is deployed uses JAXB API functionality.
JAXB is at V1.0.1 or earlier. Custom code is used to create a new JAXBContext instance:JAXBContext context = JAXBContext.newInstance.
Symptom
The information contained in this document has been moved to developerWorks Answers located here. This technote will be archived in 60 days. Please bookmark the new location.
At run time, a JAXB-related message resource bundle (properties file) might not be found by the JAXBContext class, which returns the following MissingResourceException:
[1/1/09 20:00:00:724 UTC] 00000088 SystemErr R
java.util.MissingResourceException: Can't find bundle for base name javax.xml.bind.Messages, locale en_US at
java.util.ResourceBundle.throwMissingResourceException(
ResourceBundle.java:825) at
java.util.ResourceBundle.getBundleImpl(
ResourceBundle.java(CompiledCode)) at
java.util.ResourceBundle.getBundle(ResourceBundle.java:532)
at javax.xml.bind.Messages.format(Messages.java:31)
at javax.xml.bind.Messages.format(Messages.java:16)
at javax.xml.bind.ContextFinder.searchcontextPath(
ContextFinder.java:205)
at javax.xml.bind.ContextFinder.find(
ContextFinder.java:149)
at javax.xml.bind.JAXBContext.newInstance(
JAXBContext.java:281)
at javax.xml.bind.JAXBContext.newInstance(
JAXBContext.java:238)
at org.sample.Sample.createContext(Sample.java:422)
Cause
The JAXB implementation might not be able to find the resource bundle, even when it is deployed with the same Java™ archive (JAR) file that contains the JAXB API classes. This problem is caused by the JAXB internal implementation and the use of the class loader of the target deployment container. For example, a WebSphere web container or a Java 2 Platform, Enterprise Edition (J2EE) container.
Resolving the problem
To resolve the problem, modify your custom code by explicitly providing the class loader for the current thread:
JAXBContext context = JAXBContext.newInstance(
"org.sample",this.getClass().getClassLoader());
Related information