Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
配置文件中的可选Maven属性_Maven - Fatal编程技术网

配置文件中的可选Maven属性

配置文件中的可选Maven属性,maven,Maven,我有一个“web服务测试”项目,用于测试我们的web服务。我使用maven概要文件为每个web服务生成客户端,如下所示: <profile> <!-- to run: mvn clean cxf-codegen:wsdl2java -e -Dservice=single-sign-on --> <id>single-sign-on</id> <activation> <property>

我有一个“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>

单点登录
服务
单点登录
http://example.com:8080/SingleSignOnService?wsdl
src/已生成/单点登录
com.example.single\u sign\u on
我使用cxf codegen插件实际生成客户端:

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

org.apache.cxf
cxf-codegen插件
${cxf.version}
${ws.dir}
${ws.wsdl}
-恳求
-冗长的
-前端
jaxws21
-xjc npa
-p
${ws.package}
wsdl2java
薛西斯
干细胞移植
2.8.1
符合事实的
问题是,我需要为一些web服务指定包,这样它们的对象就不会冲突,但对于大多数web服务,我不需要这样做。所以基本上我想做的是,有选择地包括

<extraarg>-p</extraarg>
<extraarg>${ws.package}</extraarg>
-p
${ws.package}

基于轮廓是否定义了特性的零件。这是可能的吗?

我不确定maven是否可以开箱即用,因为它只将
元素的第一级与配置文件中可能有的任何其他配置合并(从而替换整个
元素)

有一种解决方案,但只有在当前状态给您带来足够的痛苦时才可以使用,那就是编写您自己的版本
cxf codegen plugin
,您可以在
的顶层传递额外的
配置。比如说

<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>
<!-- 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>

单点登录
服务
单点登录
-p${ws.package}
-


然后,您的插件将负责合并真正的cfx插件所需的额外args数组

编辑 写下答案后,我想知道如果传递空的
元素,CFX插件是否会抱怨。如果可以,那么您可以在配置文件中定义变量,例如,某些配置文件将具有空值

<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>
<!-- 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>

-p
${ws.package}
...
${cfx.extra.property.1}
${cfx.extra.property.2}

感谢您的回复。我尝试像您在编辑中建议的那样传递空参数,但不幸的是,它给出了一个错误:“意外参数”。我会看看你的其他解决方案,看看它有多可行。