java.lang.NoClassDefFoundError : javax/xml/soap/SOAPException

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48626824/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 02:53:55  来源:igfitidea点击:

java.lang.NoClassDefFoundError : javax/xml/soap/SOAPException

javaxmlspringsoapspring-ws

提问by grangos

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 -jarcommand, I am receiving this exception.

我使用 Spring 创建了一个 Web 服务。在我的嵌入式 tomcat 服务器上运行它时它工作正常。但是,当我将其打包为 JAR 文件并使用java -jar命令运行它时,我收到此异常。

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

我的服务发送一个简单的soap请求,服务器响应是:

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

That's the response I get in Postman.

这就是我在 Postman 中得到的回应。

Any ideas where I can look for the problem.

我可以在哪里寻找问题的任何想法。

回答by user9712582

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

JavaSE 8 包括包java.xml.soap.
JavaSE 9 将包移动javax.xml.soap到模块java.xml.ws.
与 JEE 共享的模块(如java.xml.ws)包含在 JavaSE 9 中,但
-不赞成从 JavaSE 的未来版本中删除,并且
-不在默认模块路径中

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

一个快速的解决方法是
- 使用 JRE 8: 运行 jar $MY_JRE8_HOME/bin/java -jar my.jar,或者
- 为 JRE 9 添加一个模块:java --add-modules java.xml.ws -jar my.jar

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

从长远来看,使用类似模块的 JavaSE 项目java.xml.ws必须像其他库一样显式地包含该模块。

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

请参阅https://stackoverflow.com/a/46359097
请参阅JDK 9 迁移指南:默认情况下未解析与 JEE 共享的模块

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

(在https://spring.io/guides/gs/production-web-service/使用压缩的 SOAP Web 服务项目复制 NoClassDefError 和解决方法)

回答by Jithin U. Ahmed

Adding the following in pom file solved the issue

在 pom 文件中添加以下内容解决了问题

<!-- 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>

回答by Rish

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 ServerGithub- SpringBoot Soap Client

请参阅以下链接以获取正在运行的一段代码(SpringBootSOAPWS + Java10) Github- SpringBoot Soap Server Github- SpringBoot Soap Client

回答by prisar

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>

回答by Sudha

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

是的,在 Java 11 中 java.xml.soap 被完全删除了。 java.lang.NoClassDefFoundError: javax/xml/soap/SOAPException可以通过添加以下依赖项来删除。

<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.

但是稍后,您会遇到,javax.xml.soap.SOAPException: Unable to create SAAJ meta-factory: Provider com.sun.xml.internal.messaging.saaj.soap.SAAJMetaFactoryImpl not found。这可以通过添加以下依赖项来解决。

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

Hope, it helps!

希望能帮助到你!