java.lang.NoClassDefFoundError : javax/xml/soap/SOAPException
Asked Answered
C

8

52

I have created a Web Service using Spring. It works fine when running it on my embedded tomcat server. However when I package it as a JAR file and run it with java -jar command, I am receiving this exception.

My service sends a simple soap request and the server response is:

 "exception": "java.lang.NoClassDefFoundError",
    "message": "javax/xml/soap/SOAPException",

That's the response I get in Postman.

Any ideas where I can look for the problem.

Chole answered 5/2, 2018 at 16:14 Comment(2)
do you create a fat jar, ie. are dependencies getting packaged along with the jar?Melli
There is a class file that doesn't exist in your project. You probably didn't package your jar dependencies correctly. This error will come up if there is a missing class file.Amoeboid
B
43

Adding the following in pom file solved the issue

<!-- https://mvnrepository.com/artifact/javax.xml.soap/javax.xml.soap-api -->
<dependency>
    <groupId>javax.xml.soap</groupId>
    <artifactId>javax.xml.soap-api</artifactId>
    <version>1.4.0</version>
</dependency>
Beaux answered 30/12, 2018 at 7:58 Comment(2)
worked for me. My SOAP-API-Client Code (Springboot WAR) was running fine through "mvn spring-boot:run" but throwing this error on Tomcat 8.5. However not sure what causes "mvn spring-boot:run" to succeed in first place. Can it be that local JDK/JRE or Maven's underlying jar plays some role there ?Firstrate
worked for me. jdk 9; javax.xml.soap:javax.xml.soap-api 1.4.0; and also com.sun.xml.messaging.saaj:saaj-impl 1.5.1; as mentioned by HarisudhaThamora
W
35

JavaSE 8 includes package java.xml.soap.
JavaSE 9 moved package javax.xml.soap to the module java.xml.ws.
Modules shared with JEE (like java.xml.ws) are included in JavaSE 9, but are
- deprecated for removal from a future version of JavaSE, and
- not on the default module path.

A quick workaround is to either
- run the jar with JRE 8: $MY_JRE8_HOME/bin/java -jar my.jar, or
- add a module for JRE 9: java --add-modules java.xml.ws -jar my.jar

Longer term, JavaSE projects that use modules like java.xml.ws must explicitly include the module like other libraries.

See https://stackoverflow.com/a/46359097
See JDK 9 Migration Guide: Modules Shared with JEE Not Resolved by Default

(Reproduced NoClassDefError and workarounds with zipped SOAP web service project at https://spring.io/guides/gs/producing-web-service/)

Webby answered 27/4, 2018 at 22:46 Comment(0)
A
34

Yes, In Java 11 java.xml.soap was completely removed. java.lang.NoClassDefFoundError: javax/xml/soap/SOAPException can be removed by adding the following dependency.

<dependency>
    <groupId>jakarta.xml.soap</groupId>
    <artifactId>jakarta.xml.soap-api</artifactId>
    <version>2.0.0-RC3</version>
</dependency>

But later, you will encounter , javax.xml.soap.SOAPException: Unable to create SAAJ meta-factory: Provider com.sun.xml.internal.messaging.saaj.soap.SAAJMetaFactoryImpl not found. This can be solved by adding the following dependency.

<dependency>
    <groupId>com.sun.xml.messaging.saaj</groupId>
    <artifactId>saaj-impl</artifactId>
    <version>1.5.1</version>
</dependency>

Hope, it helps!

Aleida answered 17/4, 2020 at 16:57 Comment(1)
I can confirm that for Java 11 the implementation is missing: com.sun.xml.messaging.saaj:saaj-impl. We did not need the soap-api definition.Fess
A
17

Add the following dependencies, it should work then

<dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.3.0</version>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-core</artifactId>
        <version>2.3.0</version>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-impl</artifactId>
        <version>2.3.0</version>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.messaging.saaj</groupId>
        <artifactId>saaj-impl</artifactId>
        <version>1.5.0</version>
    </dependency>
    <dependency>
        <groupId>javax.xml.ws</groupId>
        <artifactId>jaxws-api</artifactId>
        <version>2.2.6</version>
    </dependency>

Refer the following links for a running piece of code (SpringBootSOAPWS + Java10) Github- SpringBoot Soap Server Github- SpringBoot Soap Client

Alkylation answered 27/6, 2019 at 17:48 Comment(0)
B
15

I imported this one to sort out the issue: https://mvnrepository.com/artifact/javax.xml.soap/javax.xml.soap-api/1.4.0

Benoni answered 19/9, 2018 at 21:42 Comment(0)
D
7

Adding this dependency will solve the issue.

    <dependency>
        <groupId>com.sun.xml.messaging.saaj</groupId>
        <artifactId>saaj-impl</artifactId>
        <version>1.5.0</version>
    </dependency>
Drub answered 9/1, 2020 at 20:46 Comment(0)
S
2

The JAX-WS dependency library “jaxws-api.jar” is missing. Try:

  • compile group: 'javax.xml.ws', name: 'jaxws-api', version: '2.3.1' - for gradle or:

    <dependency>
        <groupId>javax.xml.ws</groupId>
        <artifactId>jaxws-api</artifactId>
        <version>2.3.1</version>
    </dependency>
    
Skirr answered 9/4, 2021 at 12:1 Comment(0)
S
0

I know this is already closed for all above people but I am still facing this issue even though I have added jakarta-xml.soap-api and saaj jars in classpath.

Anything that I am missing to make it work.Tried out using javax-.xml-soap-api as well instead of jakarta jar but still same error.Somehow its not able to identify the jar.

Stet answered 28/9, 2022 at 13:5 Comment(3)
I know this is a bit late, but are you by chance using the 4.x versions of the Jakarta libraries? I'm currently wrestling with that since Jakarta's package name changed with that version.Thorndike
Same here..just started with 4.x upgrade and stuck with no-arg constructor issue for ProviderImplStet
I ended up going back to an older Jakarta version. Until everything I use, uses the 4.x version I'll have to stick with this. Hoping when we move to Spring 3.x it may be more feasible to use Jakarta 4.xThorndike

© 2022 - 2024 — McMap. All rights reserved.