How to resolve java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
To remove the java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException, add the JAXB API to your classpath.
For Maven:
For Gradle:
That's it! They are the dependency configurations your project needs to work with JAXB classes for Java 9+!
Know your JAXB: An overview with Java 9+
JAXB was no longer included in Java 9, creating a gap for applications relying on it. To use it, you'll have to manually add it. In addition, remember to update package names from javax.xml.bind to jakarta.xml.bind after Java 11+.
For Java 9 & 10:
Set JVM flags to include JAXB:
To add all EE modules:
Warning! This quick fix is not the best solution long-term.
For Java 11 and above
Instead, update your dependencies. Maven:
Gradle:
Remember, JAXB 2.3.1 made javax.activation
obsolete. If you still need activation framework:
Java 8 to 9+ seamless transition
When migrating from Java 8 to 9+, include an alternative JAXB provider such as EclipseLink MOXy to ease the migration process:
Then set a system property for the JAXB context factory:
Beware! Avoid deprecated com.sun
classes and always use GlassFish's JAXB RI.
Staying ahead of Java's curve
Java offers new challenges and opportunities with each update. Review JEP 261 to understand Java's modularity system and its impact on your Java EE modules, including JAXB.
Java 9+ challenges may be around the corner but so are the sleek and efficient modular designs it intends to adopt. Strategise your migration and dependency management to not just address NoClassDefFoundError
but also follow Java's new best practices.
Remember: explicit dependency management ensures compatibility with new Java releases as well as older versions!
Was this article helpful?