如何使cxf-codegen-plugin从jakarta.xml.ws生成Web服务?

问题描述

从Java 8迁移到Java 11。

将cxf-codegen-plugin从版本3.2.0更新到了3.3.6。

Plugin仍然使用来自javax.jws。*而不是jakarta.jws。*的软件包从wsdl文件生成Java存根:

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;

/**
 * This class was generated by Apache CXF 3.3.6
 * 2020-08-12T19:22:40.406+02:00
 * Generated source version: 3.3.6
 *
 */

我误认为javax.jws已过时,应更改为jakarta.jws吗?

如何用所需的软件包完成代码生成?

解决方法

尝试在生成源阶段使用 maven-replacer-plugin,在我的情况下,我在目标文件夹上生成客户端文件,然后在那里替换包

            <plugin>
            <groupId>com.google.code.maven-replacer-plugin</groupId>
            <artifactId>maven-replacer-plugin</artifactId>
            <version>1.4.1</version>
            <executions>
                <execution>
                    <id>replace-for-jakarta</id>
                    <phase>process-sources</phase>
                    <goals>
                        <goal>replace</goal>
                    </goals>
                    <configuration>
                        <filesToInclude>target/generated/**/*.java</filesToInclude>
                        <preserveDir>true</preserveDir>
                        <replacements>
                            <replacement>
                                <token>javax.jws</token>
                                <value>jakarta.jws</value>
                            </replacement>
                        </replacements>
                    </configuration>
                </execution>
            </executions>
        </plugin>

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...