Why Java Cries "NoClassDefFoundError: javax/xml/bind/JAXBException" and What to Do About It in 2025?
\n\nHave you ever encountered a situation where your Java application, which worked like clockwork yesterday, crashes today with the frightening error java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException? If so, you are not alone. This question has gathered thousands of views on Stack Overflow, and the demand for a solution hasn't dropped even in 2025. The issue stems from fundamental changes in the Java ecosystem that occurred several years ago but still haunt developers.
In this article, we won't just give you a "quick fix" — we'll break down why this error occurs and show you three reliable ways to fix it. You'll learn how to properly configure Maven, Gradle, or JVM arguments to get your application working again. Let's go!
\n\nThe Root of the Evil: Java 9 and the Module System
\n\nIt all started with Java 9 (released in 2017). In this version, Oracle introduced the module system (Project Jigsaw). Many packages that were previously part of the standard library (JDK) were moved to separate modules or removed entirely. One of these "outcasts" was the package javax.xml.bind (JAXB — Java Architecture for XML Binding).
In Java 8 and older, JAXB was available "out of the box." Starting with Java 9, it became optional. And in Java 11, it was completely removed from the JDK. If you write code that uses javax.xml.bind.JAXBContext, JAXBException, or Marshaller, and run it on Java 11+, you will guaranteed get NoClassDefFoundError.
Important: NoClassDefFoundError differs from ClassNotFoundException. The former occurs when the class was available at compile time but disappeared during runtime. The latter occurs when the class is not found at all.
Scenario: What the Problem Looks Like in Practice
\n\nImagine you have a simple class for working with XML:
\n\nimport javax.xml.bind.JAXBContext;\nimport javax.xml.bind.JAXBException;\nimport javax.xml.bind.Marshaller;\n\npublic class XmlProcessor {\n\n public void convertToXml(Object obj) throws JAXBException {\n JAXBContext context = JAXBContext.newInstance(obj.getClass());\n Marshaller marshaller = context.createMarshaller();\n marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);\n // ... output logic\n }\n}\n\nYou compile this code on Java 8 — everything is fine. Then you update the JDK to version 11 or 17, run the application, and see:
\n\nException in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException\n at XmlProcessor.convertToXml(XmlProcessor.java:6)\n ...\n\nSound familiar? Now let's fix it.
\n\nMethod 1: Add JAXB API as an External Dependency (Recommended)
\n\nThe most correct and modern approach is to explicitly state that your application uses JAXB. To do this, you need to add the library via a build system (Maven or Gradle).
\n\nFor Maven (pom.xml)
\n\nAdd to <dependencies>:
<dependency>\n <groupId>jakarta.xml.bind</groupId>\n <artifactId>jakarta.xml.bind-api</artifactId>\n <version>4.0.2</version>\n</dependency>\n<dependency>\n <groupId>org.glassfish.jaxb</groupId>\n <artifactId>jaxb-runtime</artifactId>\n <version>4.0.5</version>\n <scope>runtime</scope>\n</dependency>\n\nNote: Starting with Jakarta EE 9 (June 2021), the package javax.xml.bind has been renamed to jakarta.xml.bind. If your code is old and uses javax.*, you can still use