0

I have recently migrated my application to java 11 & Tomcat 9.0 & have started getting jaxb class not found exception.

caused by: java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1364)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1187)
at javax.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:122)
at javax.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:155)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:276)

I have tried tweaking pom.xml and redeployed my war file in tomcat but still the same error persists in logs.

In pom.xml I have added the following but it does not work for me

    <!-- JAXB API only -->
  <dependency>
      <groupId>jakarta.xml.bind</groupId>
      <artifactId>jakarta.xml.bind-api</artifactId>
      <version>3.0.0</version>
  </dependency>

  <!-- JAXB RI, Jakarta XML Binding -->
  <dependency>
      <groupId>com.sun.xml.bind</groupId>
      <artifactId>jaxb-impl</artifactId>
      <version>3.0.0</version>
      <scope>runtime</scope>
  </dependency>

also tried adding this in pom.xml but it also doesn't work for me.

<!-- JAXB API -->
<dependency>
    <groupId>jakarta.xml.bind</groupId>
    <artifactId>jakarta.xml.bind-api</artifactId>
    <version>2.3.2</version>
</dependency>

<!-- JAXB Runtime -->
<dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
    <version>2.3.2</version>
</dependency>

Please suggest

Scorpio
  • 23
  • 5
  • I think you need one of the dependencies in [this question](https://stackoverflow.com/q/53642287/636009), maybe `jaxb-core` (but a newer version), I'm not sure. – David Conrad Mar 24 '22 at 19:00
  • Hi , did add the same still it does not work for me . javax.xml.bind jaxb-api 2.3.0 com.sun.xml.bind jaxb-core 2.3.0 com.sun.xml.bind jaxb-impl 2.3.0 – Scorpio Mar 25 '22 at 10:22
  • I unzipped war file and modified pom and added these dependencies and recreated the war file with the updated pom and then deployed the war file in tomcat 9 but still I see this class not found error. I have checked in the webapps folder the updated pom is showing the new dependencies. PLease suggest if I am doing something incorrectly – Scorpio Mar 25 '22 at 10:24
  • When using `jakarta.xml.bind` 3.0 you also have to modify the code as the package name has changed from `javax.xml.bind` to `jakarta.xml.bind` (API and implementation). If you can modify the sources then you should make this step and then just use `org.glassfish.jaxb:jaxb-runtime:3.0.2` afterwards all the jaxb problems are gone. – Robert Mar 29 '22 at 09:38

0 Answers0