Scrivio Interview library
DebuggingIntermediate7 min read · updated 12 November 2026

After upgrading from Java 8 to 17, a service fails with java.lang.NoClassDefFoundError: javax/xml/bind/JAXBContext. Why, and what else was removed in the same way?

Java 11 removed the Java EE and CORBA modules from the JDK (JEP 320), so javax.xml.bind and its JAXBContext class no longer exist at run time, and code compiled against them fails with NoClassDefFoundError. The fix is to add JAXB as a normal dependency, an API jar plus an implementation such as the GlassFish runtime, preferably the jakarta.xml.bind versions. JAX-WS, javax.activation, javax.annotation and the transaction API went the same way, Nashorn was removed in 15, and the Applet API was deprecated for removal.

Why this question is asked

This is the first error many teams meet when they leave Java 8, and it often appears only at run time in a code path nobody tested. Interviewers ask it because it tests whether we understand what changed in the JDK between 8 and 17, and whether we can find the other time bombs before they go off in production. In this answer, we will see why the class disappeared, read the error properly, fix it with the right dependencies, look at the other removed pieces, and use jdeps and jdeprscan to find them all at once.

1Why JAXBContext Was in the JDK and Why It Left

JAXB is the Java API for XML binding: it turns XML into Java objects and back. In Java 6 it was bundled into the JDK together with other Java EE technologies such as JAX-WS for SOAP web services, the javax.activation framework and the common annotations like @PostConstruct. That was convenient, but it meant the JDK carried copies of enterprise APIs that evolved on their own schedule elsewhere.

When Java 9 introduced modules, these APIs became separate modules (java.xml.bind, java.xml.ws, java.activation, java.xml.ws.annotation, java.transaction and java.corba) and were deprecated for removal. In Java 9 and 10 they were still present but not resolved by default, so code needed --add-modules java.xml.bind. Java 11 then removed them completely through JEP 320. So on 17 there is no flag that brings them back; the classes are simply not in the runtime.

2Reading the Error

The error tells us which class is missing and when it was needed.

Text
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/JAXBContext
at com.acme.billing.InvoiceMapper.<init>(InvoiceMapper.java:21)
...
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBContext

Notice that it is NoClassDefFoundError, not just ClassNotFoundException. The reason is that our class was compiled against JAXBContext, so the JVM tries to link it while loading InvoiceMapper and fails. A ClassNotFoundException alone would mean code asked for the class by name, for example through Class.forName.

The error appears only when that path runs. A service can start fine and fail on the first invoice export, which is why these issues often reach production. It can also come from a dependency, not from our own code: an old SOAP client or XML library compiled against javax.xml.bind fails the same way.

3Fixing It With the Right Dependencies

We need two things on the class path: the API, which holds the interfaces and JAXBContext, and an implementation, which does the work. The API alone compiles but fails at run time because no provider is found.

There are two families of versions, and choosing between them is the main decision. The 2.3.x line keeps the old javax.xml.bind package name, so existing code works unchanged. The 3.x and 4.x lines use the new jakarta.xml.bind package after Java EE moved to the Eclipse Foundation, so imports must change from javax to jakarta. If the service also moves to Spring Boot 3, which uses Jakarta EE 9 and later, the jakarta versions are the right choice, and an OpenRewrite recipe can rename the imports.

XML
<!-- Preferred: Jakarta XML Binding 4 (package jakarta.xml.bind) -->
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>4.0.2</version> <!-- check the current version -->
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>4.0.5</version> <!-- runtime matching the API major version -->
<scope>runtime</scope>
</dependency>
// then in code:
import jakarta.xml.bind.JAXBContext; // was javax.xml.bind.JAXBContext

The API and runtime major versions must match: a 4.x API with a 2.3 runtime fails to find a provider. If a third-party library still imports javax.xml.bind, we either upgrade that library or keep a javax-based 2.3 API and runtime alongside for it. Spring Boot manages these versions in its BOM, so in a Boot application we usually leave the version out and let Boot choose.

4What Else Was Removed in the Same Way

JAXB is rarely the only casualty. The same JEP removed the rest of the Java EE modules and CORBA, and later releases removed or deprecated more. The table lists what to look for when moving from 8 to 17 or later, and the replacement for each.

Removed or deprecated between Java 8 and 17
WhatRemoved inReplacement
JAXB (javax.xml.bind)11, JEP 320jakarta.xml.bind-api plus jaxb-runtime
JAX-WS and SAAJ (javax.xml.ws, soap)11, JEP 320jakarta.xml.ws-api plus Metro runtime
JavaBeans Activation (javax.activation)11, JEP 320jakarta.activation-api
Common annotations (@PostConstruct)11, JEP 320jakarta.annotation-api
Java Transaction API (javax.transaction)11, JEP 320jakarta.transaction-api
CORBA (org.omg, javax.rmi)11, JEP 320No JDK replacement; third-party ORB
Nashorn JavaScript engine15, JEP 372GraalJS or a standalone Nashorn
Applet APIDeprecated for removal in 17None; applets are gone from browsers

The @PostConstruct case is sneaky. If javax.annotation is missing, an older Spring version may silently skip the init method rather than fail, so a bean starts without its setup. Nashorn removal shows up as ScriptEngineManager returning null for "nashorn" or "javascript", followed by a NullPointerException. Java 17 also strongly encapsulates JDK internals (JEP 403), so libraries that reach into sun.* classes through reflection may fail with InaccessibleObjectException; that is a different error with a different fix.

5Finding Everything Before Production Does

We do not want to discover these one by one at run time. The JDK ships two tools that scan compiled code. jdeps analyses dependencies between classes and modules; run with the newer JDK on our JAR and its dependencies, it reports packages it cannot find, such as javax.xml.bind, and with --jdk-internals it lists uses of internal APIs. jdeprscan lists uses of deprecated and removed APIs for a given release.

YAML
# Which JDK modules and packages does the app need? Missing ones show as "not found"
jdeps --multi-release 17 -summary --class-path 'lib/*' app.jar
# app.jar -> java.base
# app.jar -> not found <- javax.xml.bind was expected from the JDK
# Uses of JDK internal APIs that strong encapsulation will block
jdeps --jdk-internals --class-path 'lib/*' app.jar
# Uses of APIs deprecated or removed as of release 17
jdeprscan --release 17 --class-path 'lib/*' app.jar

Running these on every service before the upgrade turns surprises into a list of tickets. Combined with a full test run on the new JDK, which exercises the real code paths, it catches almost all of these problems before the first deployment.

6Follow-up questions

Why did the code work on Java 8 without any dependency?

Because Java 8 bundled JAXB in the JDK itself, in rt.jar. Our build never had to declare it. On 11 and later, it is an ordinary library like any other, so it must be on the class path.

Can we add --add-modules java.xml.bind on Java 17?

No. That flag only worked on Java 9 and 10, when the module still existed but was not resolved by default. Since Java 11 the module is gone, so the flag fails with a module not found error.

Why does the error mention ClassNotFoundException as the cause?

NoClassDefFoundError is thrown when the JVM cannot link a class our code was compiled against; underneath, the class loader tried to find it and threw ClassNotFoundException. The outer error tells us it was a link-time dependency, the cause tells us the loader simply did not find it.

7Conclusion

In this answer, we saw that JAXBContext disappeared because Java 11 removed the Java EE and CORBA modules under JEP 320. The fix is to add the JAXB API and a matching runtime, preferably the jakarta.xml.bind versions with the jakarta package, especially when moving to Spring Boot 3. JAX-WS, activation, common annotations and the transaction API went the same way, Nashorn was removed in 15 and the Applet API is deprecated for removal, and jdeps and jdeprscan help us find all of these before production does.

What to say in the interviewAbout 80 seconds aloud

Open with

The cause is JEP 320 in Java 11, which removed the Java EE and CORBA modules from the JDK. On Java 8, JAXB was bundled in the runtime, so the service never declared it; on 17 the javax.xml.bind classes simply are not there, and because our code was compiled against JAXBContext the JVM throws NoClassDefFoundError when it links that class.

Then, if they want more

The fix is to add JAXB as a normal dependency, both the API and an implementation, otherwise it compiles but finds no provider. I would prefer the Jakarta versions, jakarta.xml.bind-api with the GlassFish jaxb-runtime of the same major version, and rename imports from javax to jakarta, especially if Spring Boot 3 is next.

The 2.3 line keeps the javax package if a library still needs it. The same JEP removed JAX-WS, javax.activation, the common annotations like PostConstruct and the transaction API, and CORBA. Later, Nashorn was removed in 15 and the Applet API was deprecated for removal.

To find all of them up front I run jdeps on the jar and its dependencies with the new JDK, jdeps --jdk-internals for internal APIs, and jdeprscan for the target release.

About this answer

Last updated
12 November 2026
Versions it names
Java 11, Java 9, Java 8, Spring Boot 3
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. 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 "After upgrading from Java 8 to 17, a service fails with java.lang.NoClassDefFoundError...": https://scrivio-interview-library.netlify.app/java/java-versions/74fc4449db/