Powered by Blogger.

Solved: Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException

>> Saturday, May 29, 2021

when i run my Simple Spring Boot Application i have faced the below exception in the console. 

Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606) ~[na:na]
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168) ~[na:na]
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) ~[na:na]
	... 32 common frames omitted

The JAXB APIs are considered to be Java EE APIs and therefore are no longer contained on the default classpath in Java SE 9. In Java 11, they are completely removed from the JDK. Java 9 introduces the concepts of modules, and by default, the java.se aggregate module is available on the classpath (or rather, module-path). 

As the name implies, the java.se aggregate module does not include the Java EE APIs that have been traditionally bundled with Java 6/7/8. Fortunately, these Java EE APIs that were provided in JDK 6/7/8 are still in the JDK, but they just aren't on the classpath by default. The extra Java EE APIs are provided in the following modules:

java.xml.bind  << This one contains the JAXB APIs
Proper long-term solution: (JDK 9 and beyond)

Proper long-term solution: (JDK 9 and beyond)
The Java EE API modules listed above are all marked @Deprecated(forRemoval=true)
because they are scheduled for removal in Java 11. So the --add-module approach will no longer work in Java 11 out-of-the-box.

What you will need to do in Java 11 and forward is include your own copy of the Java EE APIs on the classpath or module path. For example, you can add the JAX-B APIs as a Maven dependency like this:
  1. <!-- API, java.xml.bind module -->
  2. <dependency>
  3. <groupId>jakarta.xml.bind</groupId>
  4. <artifactId>jakarta.xml.bind-api</artifactId>
  5. <version>2.3.2</version>
  6. </dependency>
  8. <!-- Runtime, com.sun.xml.bind module -->
  9. <dependency>
  10. <groupId>org.glassfish.jaxb</groupId>
  11. <artifactId>jaxb-runtime</artifactId>
  12. <version>2.3.2</version>
  13. </dependency>

Source: StackOverflow.

Related Posts Plugin for WordPress, Blogger...
© javabynataraj.blogspot.com from 2009 - 2022. All rights reserved.