Quick revision
The short answer
JAXB, the javax.xml.bind API, used to be bundled with the JDK as part of its Java EE modules; it was deprecated in Java 9 and removed in Java 11 by JEP 320, so on Java 17 the classes simply do not exist. Today we use Jakarta XML Binding: the jakarta.xml.bind-api dependency plus an implementation such as org.glassfish.jaxb:jaxb-runtime, with imports changed from javax.xml.bind to jakarta.xml.bind, which Spring Boot 3 and later expect. For simple mappings, Jackson's XML module is an alternative.
What to remember
In this answer, we saw that JAXB shipped inside the JDK until it was deprecated in Java 9 and removed in Java 11 by JEP 320, which is why javax.xml.bind code fails on Java 17. Its successor is Jakarta XML Binding: the jakarta.xml.bind-api dependency plus an implementation such as org.glassfish.jaxb:jaxb-runtime, with imports changed to jakarta.xml.bind as Jakarta EE 9 renamed the packages, which Spring Boot 3 and later require. Classes generated from XSDs are regenerated with jakarta versions of xjc and its plugins, and Jackson's XML module is a simpler alternative for plain mappings.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
JAXB, the javax.xml.bind API, used to be bundled with the JDK as part of its Java EE modules; it was deprecated in Java 9 and removed in Java 11 by JEP 320, so on Java 17 the classes simply do not exist. Today we use Jakarta XML Binding: the jakarta.xml.bind-api dependency plus an implementation such as org.glassfish.jaxb:jaxb-runtime, with imports changed from javax.xml.bind to jakarta.xml.bind, which Spring Boot 3 and later expect. For simple mappings, Jackson's XML module is an alternative.
Why this question is asked
This is one of the most common failures when old services move to a modern Java version. Code that has worked for ten years suddenly does not compile, or it compiles against an old jar and fails at runtime with NoClassDefFoundError or a missing implementation error. Interviewers ask it because the answer shows whether we understand the history of Java EE inside the JDK and the Jakarta rename. In this answer, we will see what JAXB is, why it left the JDK, what the failure looks like, how to migrate to Jakarta XML Binding including code generation, and when Jackson XML is the simpler choice.
1A Quick Recap of JAXB
JAXB, the Java Architecture for XML Binding, maps Java classes to XML and back. We annotate a class with @XmlRootElement, @XmlElement and @XmlAttribute, create a JAXBContext for it, and use a Marshaller to write objects as XML and an Unmarshaller to read XML into objects. It can also generate classes from an XSD with the xjc tool, which is how many SOAP clients and partner integrations were built.
From Java 6 to Java 10, JAXB shipped inside the JDK, together with other Java EE pieces such as JAX-WS for SOAP web services. So code could use javax.xml.bind without any dependency at all, and many builds never declared one.
2Why It Left the JDK
Java EE was a separate platform with its own release cycle, and keeping copies of its APIs inside the JDK meant they were often out of date and made the JDK bigger. When the module system arrived in Java 9, these APIs became the java.xml.bind module and were deprecated for removal and not resolved by default. JEP 320 then removed the Java EE and CORBA modules entirely in Java 11.
Meanwhile, Oracle handed Java EE to the Eclipse Foundation, where it became Jakarta EE. Because Oracle kept the javax trademark, Jakarta EE 9 renamed every package from javax.* to jakarta.*, so javax.xml.bind became jakarta.xml.bind. Jakarta EE 10 and 11 use Jakarta XML Binding 4.0.
| Java or Jakarta version | Where JAXB lives | Package |
|---|---|---|
| Java 6 to 8 | inside the JDK | javax.xml.bind |
| Java 9 and 10 | JDK module, deprecated, not resolved by default | javax.xml.bind |
| Java 11 and later (JEP 320) | removed; add a library | javax.xml.bind (old jars) |
| Jakarta EE 9 | Jakarta XML Binding 3.0 | jakarta.xml.bind |
| Jakarta EE 10 and 11 | Jakarta XML Binding 4.0 | jakarta.xml.bind |
3What the Failure Looks Like
If the build has no JAXB dependency, compilation on Java 17 fails because the package does not exist. If an old javax API jar is on the classpath but no implementation, compilation succeeds and the error moves to runtime.
The second message is the confusing one: the API is there, but the implementation used to be found inside the JDK and now is not. Both say the same thing: JAXB is now an ordinary library we must add.
4Migrating to Jakarta XML Binding
The modern fix has three parts: add the API and an implementation, change the imports, and regenerate any classes produced from XSDs. With Maven, the dependencies look like this; check the current 4.0.x versions for your platform.
Spring Boot 3 and 4 manage these versions for us through their dependency management, so we usually add the dependencies without a version, and Spring's own XML support, such as Jaxb2Marshaller and the JAXB message converter, uses the jakarta packages. Mixing old javax.xml.bind classes with a Spring Boot 3 application therefore does not work; everything has to move together. Tools such as OpenRewrite have recipes that rename the imports automatically across a code base.
Classes generated from an XSD need the jakarta versions of the generator. The xjc tool comes from org.glassfish.jaxb:jaxb-xjc 4.x, and the Maven plugins have jakarta-compatible major versions (for example the org.jvnet.jaxb plugin family or the codehaus jaxb2-maven-plugin 3.x); check the plugin documentation for the version that produces jakarta annotations. After regenerating, the generated sources import jakarta.xml.bind.annotation and the rest of the code follows.
5When Jackson XML Is the Simpler Choice
Not every use of JAXB needs a full JAXB replacement. If the code only maps a few plain classes to simple XML, and the team already uses Jackson for JSON, Jackson's XML module (jackson-dataformat-xml) maps the same classes with an XmlMapper and familiar annotations. It is a natural fit in Spring applications, where Jackson is already present. For XSD-driven work, strict namespaces or SOAP, Jakarta XML Binding remains the better tool, because it understands schemas directly.
6Follow-up questions
Can I just add the old javax.xml.bind jars to make Java 17 work?
Yes, the javax-era API and implementation 2.3.x jars still exist and work on Java 17 for a non-Jakarta application. It is a valid short-term fix, but those versions get no new features, and any move to Spring Boot 3 or a Jakarta EE 10 server will force the jakarta rename anyway, so it only delays the work.
Does JAX-WS have the same problem?
Yes. JAX-WS, the SOAP web services API, was removed from the JDK by the same JEP 320 and became Jakarta XML Web Services in the jakarta.xml.ws package. SOAP clients generated with wsimport need regenerating with the Jakarta tooling, for example the Metro implementation or Apache CXF 4.
Is JAXBContext expensive to create?
Yes, creating a JAXBContext inspects all the classes and builds metadata, which can take tens of milliseconds or more. It is thread-safe, so we create it once and reuse it, while Marshaller and Unmarshaller objects are cheap and not thread-safe, so we create those per use.
7Conclusion
In this answer, we saw that JAXB shipped inside the JDK until it was deprecated in Java 9 and removed in Java 11 by JEP 320, which is why javax.xml.bind code fails on Java 17. Its successor is Jakarta XML Binding: the jakarta.xml.bind-api dependency plus an implementation such as org.glassfish.jaxb:jaxb-runtime, with imports changed to jakarta.xml.bind as Jakarta EE 9 renamed the packages, which Spring Boot 3 and later require. Classes generated from XSDs are regenerated with jakarta versions of xjc and its plugins, and Jackson's XML module is a simpler alternative for plain mappings.
Open with
JAXB used to be part of the JDK. From Java 6 it shipped as one of the Java EE APIs bundled with Java SE, so code could use javax.xml.bind without any dependency.
Then, if they want more
In Java 9 it became a module that was deprecated and not resolved by default, and JEP 320 removed it, together with JAX-WS and CORBA, in Java 11. So on Java 17 the package is simply not there: either compilation fails, or if an old API jar is present, you get a runtime error saying no JAXB implementation was found.
At the same time, Java EE moved to the Eclipse Foundation as Jakarta EE, and in Jakarta EE 9 all javax packages were renamed to jakarta, so the modern API is Jakarta XML Binding in jakarta.xml.bind, version 4 for Jakarta EE 10 and 11.
The fix is to add jakarta.xml.bind-api plus an implementation, usually org.glassfish.jaxb jaxb-runtime, change the imports, and regenerate any XSD-generated classes with the jakarta version of xjc or the Maven plugin. Spring Boot 3 and later manage these versions and expect the jakarta packages, so it all has to move together; OpenRewrite can automate the renames.
If the mapping is simple and the team already uses Jackson, Jackson's XML module is a lighter alternative.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Spring Boot 3, Java 11, Java 17, Java 9
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "javax.xml.bind (JAXB) code that compiled on Java 8 fails on Java 17. Why, and what...": https://scrivio-interview-library.netlify.app/java/xml-processing/204cfec998/