首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >配置文件中的可选Maven属性

配置文件中的可选Maven属性
EN

Stack Overflow用户
提问于 2014-02-04 18:28:23
回答 1查看 982关注 0票数 0

我有"web服务测试“项目,我用它来测试我们的web服务。我使用maven配置文件为每个web服务生成客户机,如下所示:

代码语言:javascript
复制
<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来实际生成客户机:

代码语言:javascript
复制
<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服务,我不需要。所以基本上我想要做的是在某种程度上包括

代码语言:javascript
复制
<extraarg>-p</extraarg>
<extraarg>${ws.package}</extraarg>

部分基于配置文件是否定义了属性。这个是可能的吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-04 18:49:52

我不确定这是否可以用maven实现,因为它只将<configuration>元素的第一层与配置文件中的任何其他配置合并(从而替换了整个<wsdlOptions>元素)。

一个解决方案,但只有在当前状态给您带来足够痛苦的情况下,才能编写自己的cxf-codegen-plugin版本,在该版本中,您可以在<config>的顶层传递额外的<myextraargs>配置。例如

代码语言:javascript
复制
<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>

-

代码语言:javascript
复制
<!-- 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插件是否会发出抱怨。如果可以的话,您可以在配置文件中定义变量,一些配置文件将有一个空值,例如

代码语言:javascript
复制
<!-- 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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21560448

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档