How to fix java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory
I’m getting the following exception when running my project on Java 11. It was working fine with Java 8. How do I fix it?
Caused by: java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory
You’re trying to use JAXB APIs that were included previously, but removed in Java 11. If you’re using Maven, you can add these dependencies directly. The latest stable release of Eclipse Implementation of JAXB is available and here’s how to use it with Maven.
<dependency> <groupId>jakarta.xml.bind</groupId> <artifactId>jakarta.xml.bind-api</artifactId> <version>3.0.0</version> </dependency> <dependency> <groupId>com.sun.xml.bind</groupId> <artifactId>jaxb-impl</artifactId> <version>3.0.0</version> </dependency>
Java developers can use Jakarta XML Binding to map XML to Java code in an efficient and consistent manner. Java programmers who use the Jakarta XML binding are more productive because they can write less code and do not need to be XML gurus. Jakarta XML Binding makes it easy for developers to use XML and Web Services technologies to extend their applications.