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

huangapple go评论75阅读模式
英文:

How make cxf-codegen-plugin generate Webservices from jakarta.xml.ws?

问题

迁移从Java 8到Java 11。

将cxf-codegen-plugin从版本3.2.0升级到3.3.6。

插件仍然使用javax.jws.*而不是jakarta.jws.*从wsdl文件生成Java存根:

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

/**

  • 此类由Apache CXF 3.3.6生成
  • 2020-08-12T19:22:40.406+02:00
  • 生成的源代码版本:3.3.6

*/

我是否理解错误,即javax.jws已被弃用,应该更改为jakarta.jws?

我如何实现使用所需包生成代码?

英文:

Migrating from Java 8 to Java 11.

Updated cxf-codegen-plugin from version 3.2.0 to 3.3.6.

Plugin still generates Java stubs from wsdl files using packages from javax.jws.* instead of from jakarta.jws.*:

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
 *
 */

Am I getting it wrong that javax.jws is deprecated and should be changed to jakarta.jws?

And how do I accomplish code generation with desired packages?

答案1

得分: 8

问题已在CXF-8371中解决。

如果您升级到版本大于4.0.0,它将生成jakarta.jws而不是javax.jws。

英文:

Issue has been resolved in CXF-8371

If you upgrade to version >4.0.0 it will generate jakarta.jws instead of javax.jws.

答案2

得分: 5

尝试在生成源代码阶段使用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>
英文:

Try using maven-replacer-plugin at generated-source phase, in my case I generate client files on target folder and then replace package there

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

答案3

得分: 1

在我们的情况下,配置如下:

<configuration>
    <filesToInclude>${project.build.directory}/generated-sources/cxf/**/*.java</filesToInclude>
    <preserveDir>true</preserveDir>
    <replacements>
        <replacement>
            <token>javax.xml.bind</token>
            <value>jakarta.xml.bind</value>
        </replacement>
        <replacement>
            <token>javax.annotation</token>
            <value>jakarta.annotation</value>
        </replacement>
        <replacement>
            <token>javax.jws</token>
            <value>jakarta.jws</value>
        </replacement>
        <replacement>
            <token>javax.xml.ws</token>
            <value>jakarta.xml.ws</value>
        </replacement>
    </replacements>
</configuration>
英文:

in our case the configuration was like this:

&lt;configuration&gt;
                            &lt;filesToInclude&gt;${project.build.directory}/generated-sources/cxf/**/*.java&lt;/filesToInclude&gt;
                            &lt;preserveDir&gt;true&lt;/preserveDir&gt;
                            &lt;replacements&gt;
                                &lt;replacement&gt;
                                    &lt;token&gt;javax.xml.bind&lt;/token&gt;
                                    &lt;value&gt;jakarta.xml.bind&lt;/value&gt;
                                &lt;/replacement&gt;
                                &lt;replacement&gt;
                                    &lt;token&gt;javax.annotation&lt;/token&gt;
                                    &lt;value&gt;jakarta.annotation&lt;/value&gt;
                                &lt;/replacement&gt;
                                &lt;replacement&gt;
                                    &lt;token&gt;javax.jws&lt;/token&gt;
                                    &lt;value&gt;jakarta.jws&lt;/value&gt;
                                &lt;/replacement&gt;
                                &lt;replacement&gt;
                                    &lt;token&gt;javax.xml.ws&lt;/token&gt;
                                    &lt;value&gt;jakarta.xml.ws&lt;/value&gt;
                                &lt;/replacement&gt;
                            &lt;/replacements&gt;
                        &lt;/configuration&gt;

huangapple
  • 本文由 发表于 2020年8月13日 04:16:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/63384143.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定