This question already has an answer here:
- How to resolve java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException in Java 9 19 answers
- Replacements for deprecated JPMS modules with Java EE APIs 4 answers
I'm trying to deserialize XML data into a Java content tree using JAXB, validating the XML data as it is unmarshalled:
try {
JAXBContext context = JAXBContext.newInstance("com.acme.foo");
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setSchema(schema);
FooObject fooObj = (FooObject) unmarshaller.unmarshal(new File("foo.xml"));
} catch (UnmarshalException ex) {
ex.printStackTrace();
} catch (JAXBException ex) {
ex.printStackTrace();
}
When I build the project with Java 8 it's fine, but building it with Java 11 fails with a compilation error:
package javax.xml.bind does not exist
How do I fix the issue?