32

We are migrating to openjdk 11 from jdk 8. Some of our projects that uses soap to call third party apis are failing with error:

java.lang.NoClassDefFoundError: javax/xml/ws/handler/soap/SOAPHandler

After doing some research, I tried by adding dependencies :

[ references:

]

 <dependency>
        <groupId>javax.annotation</groupId>
        <artifactId>javax.annotation-api</artifactId>
    </dependency>
    <dependency>
        <groupId>xml-apis</groupId>
        <artifactId>xml-apis</artifactId>
    </dependency>
    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.3.1</version>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-core</artifactId>
        <version>2.3.0.1</version>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-impl</artifactId>
        <version>2.3.1</version>
    </dependency>
    <dependency>
        <groupId>javax.xml.soap</groupId>
        <artifactId>javax.xml.soap-api</artifactId>
        <version>1.3.5</version>
    </dependency>

Did not work. may I get an idea on the alternatives?

VictorGram
  • 2,521
  • 7
  • 48
  • 82
  • Perhaps show a snippet of your code that provokes the `java.lang.NoClassDefFoundError`. Something like a [MCVE](https://stackoverflow.com/help/mcve). – Basil Bourque Dec 05 '18 at 23:23
  • It looks like you forgot to include [jaxws-api](https://mvnrepository.com/artifact/javax.xml.ws/jaxws-api/2.2). – David Conrad Dec 05 '18 at 23:29

3 Answers3

51

Switch to jakarta.xml.ws.handler.soap.SOAPHandler and include jakarta.xml.ws-api in your dependencies:

<dependency>
    <groupId>jakarta.xml.ws</groupId>
    <artifactId>jakarta.xml.ws-api</artifactId>
    <version>4.0.0</version>
</dependency>

If you are still on versions use javax instead of jakarta, include jaxws-api in your dependencies:

<dependency>
    <groupId>javax.xml.ws</groupId>
    <artifactId>jaxws-api</artifactId>
    <version>2.3.1</version>
</dependency>

Jakarta EE 9, which moved the API namespace from javax to jakarta, was released on December 8, 2020 which happens to fall between the releases of Java 15 and Java 16, but it will really depend more on your other dependencies than the version of Java you're using.

David Conrad
  • 15,432
  • 2
  • 42
  • 54
  • 6
    If you are using Microsoft EWS Library and you get the same exception this dependency helps resolve the issue. – Waqas Sep 14 '20 at 05:33
36

The javax APIs were transitioned to Jakarta, so in 2020 the proper dependency is the following:

<dependency>
    <groupId>jakarta.xml.ws</groupId>
    <artifactId>jakarta.xml.ws-api</artifactId>
    <version>2.3.3</version>
</dependency>

Here's an article summarizing what happened: Java Magazine - Transition from Java EE to Jakarta EE

And here's a very useful table with mappings between the old artifacts and the new one.

JohnEye
  • 6,436
  • 4
  • 41
  • 67
2

Since this is the first result on google, my issue was due to having a jar, that required javax.xml.ws classes, on the Tomcat common folder /usr/local/tomcat/lib.

The Tomcat classloader hierarchy is

      Bootstrap
          |
       System
          |
       Common
       /     \
  Webapp1   Webapp2 ...

On Java 8 the common classloader can load these classes since they are on Java JRE itself, but on Java 11, the javax.xml.ws classes are on Webapp1, and the Tomcat common classloader can not load these.

For me, the solution was to no longer deploy the jar into the Tomcat common lib folder.

froque
  • 442
  • 2
  • 13