Maven "package javax.X does not exist" (JDK 11+) - Fix Removed APIs
Code that compiled on JDK 8 fails to compile on JDK 11+ because the Java EE modules - JAXB (javax.xml.bind), JAF (javax.activation), javax.annotation, CORBA - were removed from the JDK in Java 11. They no longer ship with the runtime.
What this error means
After moving to JDK 11+ the compile fails with package javax.xml.bind does not exist (or javax.annotation, javax.activation, javax.xml.ws). The same source compiled fine on JDK 8, which still bundled these modules.
[ERROR] /src/main/java/com/example/Marshal.java:[5,22] package javax.xml.bind
does not exist
[ERROR] /src/main/java/com/example/Marshal.java:[18,5] cannot find symbol
symbol: class JAXBContext
[ERROR] Failed to execute goal ...:compile (default-compile): Compilation failureCommon causes
Java EE modules removed in JDK 11 (JEP 320)
JAXB, JAF, JTA, CORBA and friends were deprecated in JDK 9 and removed in JDK 11. On 11+ they are simply not on the classpath unless you add them as dependencies.
Relying on the JDK to provide these APIs
Code that used import javax.xml.bind.* assumed the JDK bundled it. After the removal, the import resolves to nothing without an explicit standalone artifact.
How to fix it
Add the standalone JAXB (or annotation) dependency
Pull the removed API in as a regular dependency. For JAXB, add the API plus a runtime implementation.
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>4.0.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>4.0.5</version>
</dependency>For javax.annotation, add the annotation API
The @PostConstruct/@Resource annotations moved out of the JDK too.
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>3.0.0</version>
</dependency>How to prevent it
- Add explicit dependencies for any Java EE / JAXB APIs when targeting JDK 11+.
- Migrate
javax.*imports to the maintainedjakarta.*equivalents. - Test compilation on your target JDK, not just the JDK that happened to bundle these modules.