Apache Cxf对不同包的不同服务

时间:2015-05-22 11:14:22

标签: java maven cxf

我有这样的Apache Cxf maven插件配置:

<plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-codegen-plugin</artifactId>
    <executions>
        <execution>
            <id>generate-sources</id>
            <phase>generate-sources</phase>
            <configuration>
                <defaultOptions>
                    <bindingFiles>
                        <bindingfile>${basedir}/src/main/resources/jaxb-binding.general.xml</bindingfile>
                    </bindingFiles>
                </defaultOptions>
                <sourceRoot>
                    src/main/java/my/generated/services
                </sourceRoot>
                <wsdlOptions>
                    <wsdlOption>
                        <wsdl>${server1}/Service1.svc?wsdl</wsdl>
                    </wsdlOption>
                    <wsdlOption>
                        <wsdl>${server2}/Service2?wsdl</wsdl>
                    </wsdlOption>
                </wsdlOptions>
            </configuration>
            <goals>
                <goal>wsdl2java</goal>
            </goals>
        </execution>
    </executions>
</plugin>

我基本上有两个问题,也许有人可以回答这些问题:

1)如何将这两个服务端点提取到不同的目录?现在它将是&#34; src / main / java / my / generated / services&#34;对彼此而言。我想:src / main / java / my / generated / services / service1和src / main / java / my / generated / services / service2。

2)如何设置生成的java文件包为Service1的my.generated.services.service1 +(生成的文件包名称)和Service2的my.generated.services.service2 +(生成的文件包名称)?

我尝试使用绑定文件配置它,但只找到特定命名空间的解决方案..但是没有找到更通用的东西。

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

我发现将文件生成到不同目录的最简单方法是使用两种不同的WSDL2Java插件执行,如下所示。

<plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-codegen-plugin</artifactId>
    <executions>
        <execution>
            <id>generate-sources-service1</id>
            <phase>generate-sources</phase>
            <configuration>
                <sourceRoot>${basedir}/src/main/java/my/generated/services</sourceRoot>
                <wsdlOptions>
                    <wsdlOption>
                        <wsdl>${server1}/Service1.svc?wsdl</wsdl>
                    </wsdlOption>
                </wsdlOptions>
            </configuration>
            <goals>
                <goal>wsdl2java</goal>
            </goals>
        </execution>
        <execution>
            <id>generate-sources-services2</id>
            <phase>generate-sources</phase>
            <configuration>
                <sourceRoot>${basedir}/src/main/java/my/generated/services</sourceRoot>
                <wsdlOptions>
                    <wsdlOption>
                        <wsdl>${server2}/Service2?wsdl</wsdl>
                    </wsdlOption>
                </wsdlOptions>
            </configuration>
            <goals>
                <goal>wsdl2java</goal>
            </goals>
        </execution>
    </executions>
</plugin>