Home > database >  How to solve " Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/b
How to solve " Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/b

Time:12-31

How to solve " Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException" When I run the same code with Java 15, at runtime I get errors indicating that

    Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
    at org.hibernate.boot.spi.XmlMappingBinderAccess.<init>(XmlMappingBinderAccess.java:43)
    at org.hibernate.boot.MetadataSources.<init>(MetadataSources.java:87)
    at org.hibernate.cfg.Configuration.<init>(Configuration.java:123)
    at org.hibernate.cfg.Configuration.<init>(Configuration.java:118)
    at com.hibernatedemo.Main.main(Main.java:13)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    ... 5 more


I added the pom.xml but it didn't work

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.1</version>
</dependency>

CodePudding user response:

The version 2.3.1 of jaxb-api is not compatible with Java 15. Try this:

<dependencies>
  <dependency>
    <groupId>jakarta.xml.bind</groupId>
    <artifactId>jakarta.xml.bind-api</artifactId>
    <version>2.3.3</version>
  </dependency>
  <dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
    <version>2.3.3</version>
  </dependency>
</dependencies>

If you are still experiencing issues after adding these dependencies, try cleaning and rebuilding the project to ensure that all dependencies are correctly resolved and included in the classpath.

CodePudding user response:

I downloaded and built the "jaxb-api-2.3.0.jar" file separately and my problem was solved. Thank you very much, there is nothing related to "pom.xml"

If anyone else encounters this problem, they can download the file from here. jaxb-api-2.3.0.jar

  • Related