XJC throws java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException after migrating JAXB from javax to jakarta

196 views Asked by At

What I'm trying to achieve

  • Move Spring application (not Spring boot) from Java 8 to 17 and Tomcat 8 to 10.

Issues

  • After following this question I have replaced javax libraries(mostly for xml binding) with jakarta but we have a gradle script that uses xjc and is failing with the following exception and couldn't find how to fix it.

    java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException

xjc(removeOldOutput:"yes", target: sourcesDir, binding: ${"schema"}/processPaymentBindings.jaxb{ 
     schema(dir: schema, includes:"provider/gpos/processPayment/*.xsd)
    arg(value: "-Xdefault-value"
    arg(value: "-extension")
    produces(dir: sourcesDir, includes: "**/*.java Do")
}

We use the following JAXB dependencies for tasks on Gradle for your reference:

  • jaxb: jakarta activation
  • jaxb: xmlbind
  • jaxb: impl
  • jaxb1: impl
  • jaxb: xjc
  • jaxb2: common
1

There are 1 answers

2
lance-java On

You'll need to add the following dependencies which used to be included in the standard JRE but are now third party jars

<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-xjc</artifactId>
    <version>2.3.2</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>2.3.2</version>
</dependency>