使用maven cxf plugin从wsdl生成java类

本文详细介绍了如何使用Cxf插件通过执行mvn generate-sources命令生成Java代码,包括解决常见错误的方法、如何多次执行命令、配置代理访问、处理多个wsdl以及自定义wsdl2java命令参数等技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

cxf插件使用

<build>
<plugins>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>2.1.4</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<!-- <sourceRoot>${basedir}/target/generated-sources/</sourceRoot> -->
<sourceRoot>${basedir}/src/main/java/</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/WebService.wsdl</wsdl>
<!-- <extraarg>-client</extraarg> -->
<!-- <extraarg>-verbose</extraarg> -->
</wsdlOption>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/OtherWebService.wsdl</wsdl>
<!-- <extraarg>-client</extraarg> -->
<!-- <extraarg>-verbose</extraarg> -->
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-xjc-ts</artifactId>
<version>2.2.3</version>
</dependency>
</dependencies>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.apache.cxf
</groupId>
<artifactId>
cxf-codegen-plugin
</artifactId>
<versionRange>
[2.1.4,)
</versionRange>
<goals>
<goal>wsdl2java</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>



1. 执行 mvn generate-sources,就可生成java代码。

2. error: Plugin execution not
covered by lifecycle configuration: org.apache.cxf:cxf-codegen-

plugin:2.1.2:wsdl2java (execution: generate-sources, phase:
generate-sources).

出现以上错误,添加<pluginManagement></pluginManagement>里面的内容即可解决

3. 想多次执行 mvn generate-sources,就要删除cxf-codegen-plugin-markers里的Done文档

4. 如果访问wsdl需要代理,则执行 mvn generate-sources -Dhttp.proxyHost=host -Dhttp.proxyPort=port。

注:如果是下载maven相关文件,需要代理时,要在setting.xml中设置,命令行设置没有用。

5.多个wsdl,只要在wsdlOptions里添加wsdlOption

6.<extraargs>下的<extraarg>可以选择所需的wsdl2java命令参数使用([url]http://cxf.apache.org/docs/wsdl-to-java.html[/url])

参考:[url]http://cxf.apache.org/docs/maven-cxf-codegen-plugin-wsdl-to-java.html[/url]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值