Scrivio Interview library
DebuggingIntermediate7 min read · updated 12 November 2026

After migrating to Spring Boot 3 and Jakarta, a SOAP client fails at startup with ClassNotFoundException: javax.xml.bind.JAXBElement, coming from a third-party library. How do you resolve it?

The third-party library was compiled against javax.xml.bind, but after the move to Spring Boot 3 the application only ships jakarta.xml.bind, so the old class is simply not on the classpath. We first look for a Jakarta release of the library; if none exists, we either add the old javax API and a javax runtime alongside (safe only when the library does not exchange JAXB objects with our code) or rewrite the library's bytecode with the Eclipse Transformer. For SOAP stubs we own, we regenerate them with Jakarta-based tools, and we track the legacy dependency so it is removed later.

Why this question is asked

Spring Boot 3 moved the whole stack from Java EE's javax packages to Jakarta EE's jakarta packages. Our own code is easy to migrate with search and replace or OpenRewrite, but third-party jars keep the package names they were compiled with. A SOAP client library is a classic example, because SOAP tooling generated code against javax.xml.bind for twenty years. Interviewers ask this to see whether we know that javax and jakarta are different packages, not versions. In this answer, we will see why the class is missing, go through the fixes in order of preference, and keep the workaround from becoming permanent.

1Why the Class Is Missing

Java EE was handed to the Eclipse Foundation and renamed Jakarta EE. From Jakarta EE 9 on, every API package was renamed from javax.* to jakarta.*, so javax.xml.bind.JAXBElement became jakarta.xml.bind.JAXBElement. To the JVM these are two unrelated classes that happen to have the same simple name.

Spring Boot 3 is built on Jakarta EE 9 and later, so its dependency management brings jakarta.xml.bind-api 4.x and jaxb-runtime 4.x. Before the upgrade, Spring Boot 2 brought the javax versions, so the old library found its classes by luck. After the upgrade nothing provides javax.xml.bind any more. When the library's code is loaded and it refers to javax.xml.bind.JAXBElement, the class loader cannot find it, and we get ClassNotFoundException (or NoClassDefFoundError) at startup.

Java
// inside the third-party jar, compiled years ago
import javax.xml.bind.JAXBElement; // the class the library needs
// what Spring Boot 3 puts on the classpath
import jakarta.xml.bind.JAXBElement; // a different class, different package
// at startup
// java.lang.ClassNotFoundException: javax.xml.bind.JAXBElement

We can confirm the source quickly with mvn dependency:tree and by looking at the stack trace: the frame just above the exception names a class from the library's package, not ours.

2Option 1: Find a Jakarta Version of the Library

The best fix is the one where we change nothing but a version number. Many libraries now publish a Jakarta build, either as a new major version or as a separate artifact with a classifier or a -jakarta suffix in its name. We check the library's release notes and the Maven repository before trying anything clever.

It keeps one namespace in the application, and the maintainers have tested it against the Jakarta API, so even a version with other breaking changes is usually cheaper than a workaround.

3Option 2: Run the javax API and Runtime Alongside

Because javax.xml.bind and jakarta.xml.bind are different packages, both can live on the same classpath without clashing at the class level. So we can add the old API and an old runtime just for the library.

XML
<!-- the javax API, for the legacy library only -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<!-- a javax runtime with coordinates that do not clash with jaxb-runtime 4.x -->
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.9</version> <!-- check the latest 2.3.x -->
</dependency>
Step throughOne application, two JAXB namespaces
  1. Our code and Spring Boot 3uses jakarta.xml.bind only
  2. jakarta.xml.bind-api 4.x and jaxb-runtime 4.xmanaged by Spring Boot
  3. Legacy SOAP librarycompiled against javax.xml.bind
  4. javax.xml.bind jaxb-api 2.3.1 and a javax runtimeadded only for the library

4 layers, from the top down. Step through them one at a time.

Safe only while no JAXB object crosses between the top and the bottom halves.

There is a catch with Maven coordinates. The jakarta runtime 4.x and the javax runtime 2.3.x are both published as org.glassfish.jaxb:jaxb-runtime, and Maven keeps only one version of an artifact. If we add jaxb-runtime 2.3 we silently downgrade the jakarta runtime and break our own code. That is why the snippet uses a javax runtime with different coordinates; we check that mvn dependency:tree shows both lines afterwards.

There is a second, more important catch. This only works when the library keeps its JAXB objects to itself. If the library returns a javax.xml.bind.JAXBElement and our code expects a jakarta one, or we pass it a jakarta Marshaller, the types do not match and we get ClassCastException or compile errors. So we use this option only when the library is a black box from our point of view.

4Option 3: Transform the Library With the Eclipse Transformer

When there is no Jakarta version and the library does exchange JAXB types with us, we can rewrite the jar itself. The Eclipse Transformer is a tool that reads a jar and rewrites its bytecode and resources so that references to javax.* packages point to the matching jakarta.* packages. It can run from the command line or as a Maven plugin that produces a transformed artifact.

The result is a jar that behaves as if the library had been compiled against Jakarta. The cost is that we now own a modified binary: we must store it in our artifact repository, rerun the transformation on every library upgrade, and test it, since a library that builds class names from strings at run time may still refer to javax names that the tool cannot see.

5Option 4: Regenerate the SOAP Stubs With Jakarta Tools

Often the "third-party library" is really a set of client stubs generated from a partner's WSDL, the XML document that describes a SOAP service. In that case we do not need the old jar at all. We regenerate the stubs from the WSDL with tools that target Jakarta: the jaxws-maven-plugin in its Jakarta XML Web Services line (4.x), Apache CXF 4's cxf-codegen-plugin, or, if we use Spring Web Services 4, a Jakarta JAXB code generator such as the jaxb-maven-plugin to generate the classes and WebServiceTemplate to call the service.

The generated code then uses jakarta.xml.bind and jakarta.xml.ws throughout, and it is part of our build, so the problem cannot come back. This is usually the best answer when it applies.

Step throughChoosing the fix
  1. Is there a Jakarta release of the library?
    YesUpgrade and stop hereNoContinue
  2. Are the classes generated from a WSDL we have?
    YesRegenerate with Jakarta toolsNoContinue
  3. Does the library exchange JAXB objects with our code?
    YesTransform the jar with the Eclipse TransformerNoAdd javax API and runtime alongside
  4. Record the workaroundticket, owner, enforcer rule

4 steps in order. Play them, or step through them one at a time.

6Tracking the Legacy Dependency

Options 2 and 3 are workarounds, and workarounds tend to stay forever unless someone owns them. We record the reason in the build file next to the dependency, open a ticket with an owner and a review date, and add a Maven Enforcer bannedDependencies rule that forbids javax.xml.bind everywhere except in this one module. The rule stops new code from quietly adding javax dependencies and keeps the exception visible. When the library vendor ships a Jakarta version, the ticket tells us exactly what to remove.

7Follow-up questions

Why not just change our own code back to javax?

Because Spring Boot 3, Spring Framework 6 and Hibernate 6 all use the jakarta packages and have no javax variants. Going back would mean staying on unsupported versions. The legacy library is the exception, so the fix belongs at the library.

Would adding jakarta.xml.bind-api 2.3.3 help, since it contains javax packages?

It can, because the 2.3.x releases of the jakarta.xml.bind-api artifact still contain the javax.xml.bind packages. But it has the same coordinates as the 4.x API that Spring Boot manages, so Maven would pick one and break the other side. Using the separate javax.xml.bind:jaxb-api artifact avoids that clash.

How do we test that the workaround is safe?

We run an integration test that calls the partner's service, or a recorded stub of it, through the real library and checks both the request and the parsed response. We also start the full application context in a test, because missing classes from a library often appear only when Spring initializes the bean that uses it.

8Conclusion

In this answer, we saw that the error appears because javax.xml.bind and jakarta.xml.bind are different packages and Spring Boot 3 no longer brings the javax one. We prefer a Jakarta release of the library, then regenerating SOAP stubs with Jakarta tools, then transforming the jar with the Eclipse Transformer when JAXB objects cross the boundary, and finally running the javax API and a non-clashing javax runtime alongside when the library is a black box. Whatever we choose, we record it and ban new javax dependencies so the legacy piece is removed later.

What to say in the interviewAbout 80 seconds aloud

Open with

The cause is the Jakarta rename. The library was compiled against javax.xml.bind, and Spring Boot 3 only provides jakarta.xml.bind, which is a different package, so the JVM cannot find javax.xml.bind.JAXBElement when the library loads.

Then, if they want more

My first step is to look for a Jakarta release of the library, because then the fix is just a version change.

If the library is really client stubs generated from a WSDL, I regenerate them with Jakarta tooling, for example jaxws-maven-plugin 4 or CXF 4, or generate the JAXB classes and use Spring Web Services 4, so the code is ours and uses jakarta throughout. If neither is possible, I look at whether the library passes JAXB objects to my code.

If it does not, I can add the javax API and a javax runtime next to the jakarta ones, taking care that the runtime's Maven coordinates do not clash with jaxb-runtime 4, otherwise Maven would downgrade it. If it does pass JAXB objects, I use the Eclipse Transformer to rewrite the jar to jakarta.

In either workaround case I document it, add an enforcer rule so javax does not spread, and keep a ticket to remove it when the vendor catches up.

About this answer

Last updated
12 November 2026
Versions it names
Spring Boot 3, Jakarta EE 9, Hibernate 6, Spring Boot 2
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 "After migrating to Spring Boot 3 and Jakarta, a SOAP client fails at startup with...": https://scrivio-interview-library.netlify.app/java/jaxb/74ecc7d23d/