为啥当我从 jaxws-maven-plugin 生成 wsdl 类时,由于缺少 ProviderImpl,它们无法在运行时运行?

Posted

技术标签:

【中文标题】为啥当我从 jaxws-maven-plugin 生成 wsdl 类时,由于缺少 ProviderImpl,它们无法在运行时运行?【英文标题】:Why when I generate wsdl classes from jaxws-maven-plugin they fail to run at runtime because of missing ProviderImpl?为什么当我从 jaxws-maven-plugin 生成 wsdl 类时,由于缺少 ProviderImpl,它们无法在运行时运行? 【发布时间】:2021-04-11 01:15:27 【问题描述】:

我正在使用 Maven Spring 生成类

<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>

生成了类,但是当我尝试调用它们时,它们却失败了,因为

java.lang.Exception: Unexpected exception, expected<cz.project.common.exceptions.DataBoxException> but was<javax.xml.ws.WebServiceException>
Caused by: java.lang.ClassNotFoundException: com.sun.xml.internal.ws.spi.ProviderImpl

例如,我尝试向插件和 pom 添加各种依赖项

<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-ri</artifactId>
<version>2.3.1</version>                        
</dependency>

<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>rt</artifactId>
<version>2.3.2</version>
</dependency>

<dependency>
<groupId>com.sun.org.apache.xml.internal</groupId>
<artifactId>resolver</artifactId>
<version>20050927</version>
</dependency>

但没有任何帮助。我尝试了插件的 com.sun.xml.ws 和 org.codehaus.mojo 版本

插件的完整定义是

<plugin>
                <!--groupId>com.sun.xml.ws</groupId>
                <artifactId>jaxws-maven-plugin</artifactId>
                <version>2.3.2</version-->
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxws-maven-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <id>db</id>
                        <goals>
                            <goal>wsimport</goal>
                        </goals>
                        <configuration>
                            <xnocompile>false</xnocompile>
                            <!--useJdkToolchainExecutable>false</useJdkToolchainExecutable-->
                            <keep>true</keep>
                            <!--xadditionalHeaders>true</xadditionalHeaders-->
                            <wsdlFiles>
                                <wsdlFile>$basedir/src/main/resources/wsdl/db_search.wsdl</wsdlFile>
                                <wsdlFile>$basedir/src/main/resources/wsdl/db_access.wsdl</wsdlFile>
                            </wsdlFiles>
                            <bindingFiles>
                                <bindingFile>$basedir/src/main/resources/wsdl/binding.xml</bindingFile>
                            </bindingFiles>
                            <packageName>cz.czechpoint.isds.v20.db</packageName>
                            <sourceDestDir>$project.build.directory/generated-sources/wsdl/db</sourceDestDir>
                        </configuration>
                    </execution>
                    <execution>
                        <id>dm</id>
                        <goals>
                            <goal>wsimport</goal>
                        </goals>
                        <configuration>
                            <xnocompile>false</xnocompile>
                            <!--useJdkToolchainExecutable>false</useJdkToolchainExecutable-->
                            <keep>true</keep>
                            <!--xadditionalHeaders>true</xadditionalHeaders-->
                            <wsdlFiles>
                                <wsdlFile>$basedir/src/main/resources/wsdl/dm_info.wsdl</wsdlFile>
                                <wsdlFile>$basedir/src/main/resources/wsdl/dm_operations.wsdl</wsdlFile>
                            </wsdlFiles>
                            <bindingFiles>
                                <bindingFile>$basedir/src/main/resources/wsdl/binding.xml</bindingFile>
                            </bindingFiles>
                            <packageName>cz.czechpoint.isds.v20.dm</packageName>
                            <sourceDestDir>$project.build.directory/generated-sources/wsdl/db</sourceDestDir>
                        </configuration>
                    </execution>
                </executions>
                <dependencies>

                    <dependency>
                        <groupId>com.sun.xml.ws</groupId>
                        <artifactId>jaxws-ri</artifactId>
                        <version>2.3.3</version>
                        <type>pom</type>
                    </dependency>

                    <dependency>
                        <groupId>com.sun.xml.ws</groupId>
                        <artifactId>rt</artifactId>
                        <version>2.3.2</version>
                    </dependency>

                    <dependency>
                        <groupId>com.sun.org.apache.xml.internal</groupId>
                        <artifactId>resolver</artifactId>
                        <version>20050927</version>
                    </dependency>
                </dependencies>
            </plugin>

wsdl 文件可以在https://github.com/dfridrich/CzechDataBox/tree/master/Resources 找到(这是来自不同人的不同项目,但我使用的是相同的 wsdls。)并且解释了 bindig Why is Maven generating method with 5 parameters instead of one from wsdl?

我需要添加什么来解决缺少的参考?

【问题讨论】:

【参考方案1】:

在 pom.xml 中添加新的依赖项

<dependency>
    <groupId>com.sun.xml.ws</groupId>
    <artifactId>jaxws-rt</artifactId>
    <version>2.3.3</version>
</dependency>

【讨论】:

我在插件中添加了这个 javax.xml.wsjaxws-api2.3.1 version> com.sun.xml.wsjaxws-tools2.3.1 解决它

以上是关于为啥当我从 jaxws-maven-plugin 生成 wsdl 类时,由于缺少 ProviderImpl,它们无法在运行时运行?的主要内容,如果未能解决你的问题,请参考以下文章

为啥当我从邮递员那里点击以下功能时,它会卡住?

当我从 SQL Server 代理运行 Python 脚本时,为啥它会失败?

当我从 C# 代码调用导入的 C++ 函数时,为啥会引发 AccessViolationException?

当我从 TabFragment 使用 LoaderManager 启动片段时,为啥 Tablayout 和 Viewpager 会因 NullpointerException 而崩溃?

当我从 Angular 传递 graphql 查询时,为啥 GraphQL 控制器中的参数查询为空?

当我从套接字接收到一些数据时,为啥会附加很多空格?