If you are upgrading your Java application from a lower version to Java 11, you may get the following error:
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException
The JAXB APIs are considered to be Java EE APIs, and therefore are no longer contained on the default class path in Java SE 9. In Java 11 they are completely removed from the JDK. If you are using Java 9, then the JAVA SE module named java.se is in the classpath but this module doesn't contain the JAVA EE APIs. While from Java 11 onwards, the jaxb apis, namely:
are completely removed from the Java installation. Hence, to resolve the above error, you must include the jaxb-api jar file in the classpath of your project/application.
For Maven Projects:
If you are using Maven for handling dependencies in your Java project, you will have to add the following additional dependency in your pom.xml file.
This will include the jaxb-api Jar file in your project when you will build your maven java project.
For Gradle Projects:
If you use Gradle to build your project, then add the following line to your build.gradle file,
compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.0'
For SBT Projects:
If you use SBT build tool to compile and build your java project, then add the following line to your build file,
libraryDependencies += "javax.xml.bind" % "jaxb-api" % "2.3.0"
For IVY Projects:
If you use ivy for building your java project, then add the following code line to your ivy.xml file:
<dependency org="javax.xml.bind" name="jaxb-api" rev="2.3.0"/>
If you don't use any build tool
If you are not using any build tool, then you can download the jar file from the following link: JAXB-API 2.3.0 MVN Repository and add it to your project's classpath
Once you have made the following changes, restart your Java application and the error should be resolved. So this was the solution for the java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException Error. If you are not able to understand anything, feel free to comment and we will help you resolve your error.
You Might Also Like