cxf插件使用
单wsdl
<build> <plugins> <plugin> <groupId>org.apache.cxf</groupId> <artifactId>cxf-codegen-plugin</artifactId> <version>${cxf.version}</version> <executions> <execution> <configuration> <sourceRoot> ${basedir}/target/generated-sources </sourceRoot> <wsdlOptions> <wsdlOption> <wsdl> http://www.xxx.cn/xxxWebService.asmx?wsdl </wsdl> </wsdlOption> </wsdlOptions> </configuration> <goals> <goal>wsdl2java</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
执行 mvn generate-sources,就可生成java代码。
如果访问wsdl需要代理,则执行 mvn generate-sources -Dhttp.proxyHost=host -Dhttp.proxyPort=port。
注:如果是下载maven相关文件,需要代理时,要在setting.xml中设置,命令行设置没有用。
多wsdl
多个wsdl配置,且通过命令行参数选择是否执行该插件
<!-- 利用cxf wsdl2java 生成 java代码--> <profiles> <!-- 以-Drental.w2j=xxx 激活--> <profile> <id>rental-all</id> <activation> <property> <name>rental.w2j</name> <value>all</value> </property> </activation> <build> <plugins> <!-- CXF wsdl2java generator, will plugin to the compile goal --> <plugin> <groupId>org.apache.cxf</groupId> <artifactId>cxf-codegen-plugin</artifactId> <version>${cxf-version}</version> <executions> <execution> <id>generate-sources-sd-pub</id> <phase>generate-sources</phase> <configuration> <sourceRoot>${basedir}/src/main/java</sourceRoot> <wsdlOptions> <wsdlOption> <wsdl>http://www.test.cn/AxxxSerivce.asmx?wsdl</wsdl> <bindingFiles> <bindingFile>${basedir}/src/test/resources/jaxb-binding-date.xml</bindingFile> </bindingFiles> <extraargs> <extraarg>-client</extraarg> <extraarg>-p</extraarg> <extraarg> com.test.a </extraarg> </extraargs> </wsdlOption> </wsdlOptions> </configuration> <goals> <goal>wsdl2java</goal> </goals> </execution> <execution> <id>generate-sources-sp-pub</id> <phase>generate-sources</phase> <configuration> <sourceRoot>${basedir}/src/main/java</sourceRoot> <wsdlOptions> <wsdlOption> <wsdl>http://www.test.cn/BxxxService.asmx?wsdl</wsdl> <bindingFiles> <bindingFile>${basedir}/src/test/resources/jaxb-binding-date.xml</bindingFile> </bindingFiles> <extraargs> <extraarg>-client</extraarg> <extraarg>-p</extraarg> <extraarg> com.test.b </extraarg> </extraargs> </wsdlOption> </wsdlOptions> </configuration> <goals> <goal>wsdl2java</goal> </goals> </execution> <execution> <id>generate-sources-cd-pub</id> <phase>generate-sources</phase> <configuration> <sourceRoot>${basedir}/src/main/java</sourceRoot> <wsdlOptions> <wsdlOption> <wsdl>http://www.test.cn/CxxxService.asmx?wsdl</wsdl> <bindingFiles> <bindingFile>${basedir}/src/test/resources/jaxb-binding-date.xml</bindingFile> </bindingFiles> <extraargs> <extraarg>-client</extraarg> <extraarg>-p</extraarg> <extraarg> com.test.c </extraarg> </extraargs> </wsdlOption> </wsdlOptions> </configuration> <goals> <goal>wsdl2java</goal> </goals> </execution> <execution> <id>generate-sources-sd-ts</id> <phase>generate-sources</phase> <configuration> <sourceRoot>${basedir}/src/main/java</sourceRoot> <wsdlOptions> <wsdlOption> <wsdl>http://www.test.cn/DxxxService.asmx?wsdl</wsdl> <bindingFiles> <bindingFile>${basedir}/src/test/resources/jaxb-binding-date.xml</bindingFile> </bindingFiles> <extraargs> <extraarg>-client</extraarg> <extraarg>-p</extraarg> <extraarg> com.test.d </extraarg> </extraargs> </wsdlOption> </wsdlOptions> </configuration> <goals> <goal>wsdl2java</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </profile> <profile> <id>rental-sd-pub</id> <activation> <property> <name>rental.w2j</name> <value>sd-pub</value> </property> </activation> <build> <plugins> <plugin> <groupId>org.apache.cxf</groupId> <artifactId>cxf-codegen-plugin</artifactId> <version>${cxf-version}</version> <executions> <execution> <id>generate-sources-sd-pub</id> <phase>generate-sources</phase> <configuration> <sourceRoot>${basedir}/src/main/java</sourceRoot> <wsdlOptions> <wsdlOption> <wsdl>http://www.test.cn/AxxxSerivce.asmx?wsdl</wsdl> <bindingFiles> <bindingFile>${basedir}/src/test/resources/jaxb-binding-date.xml</bindingFile> </bindingFiles> <extraargs> <extraarg>-client</extraarg> <extraarg>-p</extraarg> <extraarg> com.test.a </extraarg> </extraargs> </wsdlOption> </wsdlOptions> </configuration> <goals> <goal>wsdl2java</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </profile> <profile> <id>rental-sp-pub</id> <activation> <property> <name>rental.w2j</name> <value>sp-pub</value> </property> </activation> <build> <plugins> <!-- CXF wsdl2java generator, will plugin to the compile goal --> <plugin> <groupId>org.apache.cxf</groupId> <artifactId>cxf-codegen-plugin</artifactId> <version>${cxf-version}</version> <executions> <execution> <id>generate-sources-sp-pub</id> <phase>generate-sources</phase> <configuration> <sourceRoot>${basedir}/src/main/java</sourceRoot> <wsdlOptions> <wsdlOption> <wsdl>http://www.test.cn/BxxxService.asmx?wsdl</wsdl> <bindingFiles> <bindingFile>${basedir}/src/test/resources/jaxb-binding-date.xml</bindingFile> </bindingFiles> <extraargs> <extraarg>-client</extraarg> <extraarg>-p</extraarg> <extraarg> com.test.b </extraarg> </extraargs> </wsdlOption> </wsdlOptions> </configuration> <goals> <goal>wsdl2java</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </profile> <profile> <id>rental-cd-pub</id> <activation> <property> <name>rental.w2j</name> <value>cd-pub</value> </property> </activation> <build> <plugins> <!-- CXF wsdl2java generator, will plugin to the compile goal --> <plugin> <groupId>org.apache.cxf</groupId> <artifactId>cxf-codegen-plugin</artifactId> <version>${cxf-version}</version> <executions> <execution> <id>generate-sources-cd-pub</id> <phase>generate-sources</phase> <configuration> <sourceRoot>${basedir}/src/main/java</sourceRoot> <wsdlOptions> <wsdlOption> <wsdl>http://www.test.cn/CxxxService.asmx?wsdl</wsdl> <bindingFiles> <bindingFile>${basedir}/src/test/resources/jaxb-binding-date.xml</bindingFile> </bindingFiles> <extraargs> <extraarg>-client</extraarg> <extraarg>-p</extraarg> <extraarg> com.test.c </extraarg> </extraargs> </wsdlOption> </wsdlOptions> </configuration> <goals> <goal>wsdl2java</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </profile> <profile> <id>rental-sd-ts</id> <activation> <property> <name>rental.w2j</name> <value>sd-ts</value> </property> </activation> <build> <plugins> <!-- CXF wsdl2java generator, will plugin to the compile goal --> <plugin> <groupId>org.apache.cxf</groupId> <artifactId>cxf-codegen-plugin</artifactId> <version>${cxf-version}</version> <executions> <execution> <id>generate-sources-sd-ts</id> <phase>generate-sources</phase> <configuration> <sourceRoot>${basedir}/src/main/java</sourceRoot> <wsdlOptions> <wsdlOption> <wsdl>http://www.test.cn/DxxxService.asmx?wsdl</wsdl> <bindingFiles> <bindingFile>${basedir}/src/test/resources/jaxb-binding-date.xml</bindingFile> </bindingFiles> <extraargs> <extraarg>-client</extraarg> <extraarg>-p</extraarg> <extraarg> com.test.d </extraarg> </extraargs> </wsdlOption> </wsdlOptions> </configuration> <goals> <goal>wsdl2java</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </profile> </profiles>
说明:
1. 执行mvn generate-sources -Drental.w2j=xxx ,可以根据xxx的不同的值(all/sd-pub/cd-pub/sp-pub/sd-ts)来选择不同的profile执行
2. <extraargs>下的<extraarg>可以选择所需的wsdl2java命令参数使用(http://cxf.apache.org/docs/wsdl-to-java.html)
参考:http://cxf.apache.org/docs/maven-cxf-codegen-plugin-wsdl-to-java.html