我有"web服务测试“项目,我用它来测试我们的web服务。我使用maven配置文件为每个web服务生成客户机,如下所示:
<profile>
<!-- to run: mvn clean cxf-codegen:wsdl2java -e -Dservice=single-sign-on -->
<id>single-sign-on</id>
<activation>
<property>
<name>service</name>
<value>single-sign-on</value>
</property>
</activation>
<properties>
<ws.wsdl>http://example.com:8080/SingleSignOnService?wsdl</ws.wsdl>
<ws.dir>src/generated/single-sign-on</ws.dir>
<ws.package>com.example.single_sign_on</ws.package>
</properties>
</profile>我使用cxf-codegen-plugin来实际生成客户机:
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<configuration>
<sourceRoot>${ws.dir}</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${ws.wsdl}</wsdl>
<extraargs>
<extraarg>-impl</extraarg>
<extraarg>-verbose</extraarg>
<extraarg>-frontend</extraarg>
<extraarg>jaxws21</extraarg>
<extraarg>-xjc-npa</extraarg>
<extraarg>-p</extraarg>
<extraarg>${ws.package}</extraarg>
</extraargs>
</wsdlOption>
</wsdlOptions>
</configuration>
<executions>
<execution>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.8.1</version>
</dependency>
</dependencies>
<inherited>true</inherited>
</plugin>问题是,我需要为一些web服务指定包,这样它们的对象就不会冲突,但是对于大多数web服务,我不需要。所以基本上我想要做的是在某种程度上包括
<extraarg>-p</extraarg>
<extraarg>${ws.package}</extraarg>部分基于配置文件是否定义了属性。这个是可能的吗?
发布于 2014-02-04 18:49:52
我不确定这是否可以用maven实现,因为它只将<configuration>元素的第一层与配置文件中的任何其他配置合并(从而替换了整个<wsdlOptions>元素)。
一个解决方案,但只有在当前状态给您带来足够痛苦的情况下,才能编写自己的cxf-codegen-plugin版本,在该版本中,您可以在<config>的顶层传递额外的<myextraargs>配置。例如
<profile>
<id>single-sign-on</id>
<activation>
<property>
<name>service</name>
<value>single-sign-on</value>
</property>
</activation>
<properties>
<!-- ... -->
<!-- extra args for your plugin -->
<my.extra.args>-p ${ws.package}</my.extra.args>
</properties>
</profile>-
<!-- generic test configuration>
<plugin>
<groupId>your.group.id</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<configuration>
<sourceRoot>${ws.dir}</sourceRoot>
<myextraargs>${my.extra.args}</myextraargs>
<wsdlOptions>
<wsdlOption>
<wsdl>${ws.wsdl}</wsdl>
<extraargs>
<extraarg>...</extraarg>
</extraargs>
</wsdlOption>
</wsdlOptions>
</configuration>
<!-- ... -->
</plugin>那么您的插件将负责合并真正的cfx插件所需的额外的args数组。
编辑
写完答案后,我想知道如果您传递空的<extraarg>元素,CFX插件是否会发出抱怨。如果可以的话,您可以在配置文件中定义变量,一些配置文件将有一个空值,例如
<!-- profile 1 -->
<properties>
<!-- ... -->
<cfx.extra.property.1>-p</cfx.extra.property.1>
<cfx.extra.property.2>${ws.package}</cfx.extra.property.2>
</properties>
<!-- profile 2 -->
<properties>
<!-- ... -->
<cfx.extra.property.1></cfx.extra.property.1>
<cfx.extra.property.2></cfx.extra.property.2>
</properties>
<!-- ... -->
<extraargs>
<extraarg>...</extraarg>
<extraarg>${cfx.extra.property.1}</extraarg>
<extraarg>${cfx.extra.property.2}</extraarg>
</extraargs>https://stackoverflow.com/questions/21560448
复制相似问题