You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JDK17+SpringBoot环境下jaxws-maven-plugin无法生成@WebServiceClient类

解决JDK 17下jaxws-maven-plugin无法生成@WebServiceClient类的问题

核心原因

JDK 9及以上版本通过模块化移除了内置的JAX-WS组件(包括wsimport工具),旧版jaxws-maven-plugin依赖JDK内置组件工作,在JDK17环境下会缺失关键功能,导致仅生成实体Bean而不生成带@WebServiceClient注解的客户端入口类。


方案一:升级并配置适配JDK17的jaxws-maven-plugin

使用官方维护的适配JDK9+的插件版本,同时补充JAX-WS依赖并开启客户端类生成参数:

<build>
    <plugins>
        <plugin>
            <groupId>com.sun.xml.ws</groupId>
            <artifactId>jaxws-maven-plugin</artifactId>
            <!-- 选用适配JDK17的稳定版本,如2.3.5或更高 -->
            <version>2.3.5</version>
            <executions>
                <execution>
                    <goals>
                        <goal>wsimport</goal>
                    </goals>
                    <configuration>
                        <!-- 替换为你的WSDL地址或本地文件路径 -->
                        <wsdlUrls>
                            <wsdlUrl>http://example.com/service?wsdl</wsdlUrl>
                        </wsdlUrls>
                        <!-- 指定生成代码的包名 -->
                        <packageName>com.yourcompany.soap.client</packageName>
                        <!-- 保留生成的源码 -->
                        <keep>true</keep>
                        <!-- 关键:开启客户端类生成,对应@WebServiceClient注解类 -->
                        <genJws>true</genJws>
                        <!-- 指定生成代码的输出目录 -->
                        <destDir>${project.build.directory}/generated-sources/jaxws</destDir>
                    </configuration>
                </execution>
            </executions>
            <!-- 补充JAX-WS运行时和工具依赖,JDK17无内置 -->
            <dependencies>
                <dependency>
                    <groupId>com.sun.xml.ws</groupId>
                    <artifactId>jaxws-rt</artifactId>
                    <version>2.3.5</version>
                </dependency>
                <dependency>
                    <groupId>com.sun.xml.ws</groupId>
                    <artifactId>jaxws-tools</artifactId>
                    <version>2.3.5</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
    <!-- 将生成的源码目录添加到Maven编译路径 -->
    <sources>
        <source>${project.build.directory}/generated-sources/jaxws</source>
    </sources>
</build>

方案二:改用Apache CXF Codegen Plugin(更稳定的JDK17适配)

如果jaxws-maven-plugin仍有兼容问题,推荐使用Apache CXF的代码生成插件,对JDK17支持更完善:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-codegen-plugin</artifactId>
            <!-- 选用适配JDK17的稳定版本 -->
            <version>3.6.2</version>
            <executions>
                <execution>
                    <id>generate-soap-client</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>wsdl2java</goal>
                    </goals>
                    <configuration>
                        <wsdlOptions>
                            <wsdlOption>
                                <!-- 替换为你的WSDL地址或本地路径 -->
                                <wsdl>http://example.com/service?wsdl</wsdl>
                                <!-- 指定生成代码的包名 -->
                                <packageName>com.yourcompany.soap.client</packageName>
                                <!-- 生成带@WebServiceClient注解的客户端类 -->
                                <extraargs>
                                    <extraarg>-client</extraarg>
                                </extraargs>
                            </wsdlOption>
                        </wsdlOptions>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <!-- 添加生成源码目录到编译路径 -->
    <sources>
        <source>${project.build.directory}/generated-sources/cxf</source>
    </sources>
</build>

验证步骤

  1. 执行mvn clean generate-sources命令,检查生成目录下是否出现带@WebServiceClient注解的类(通常类名与WSDL中的服务名一致);
  2. 确认生成的代码被Maven正确识别为源码,可正常编译。

内容的提问来源于stack exchange,提问作者rkhot

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 13:46:04