修改从wsdl生成的java类的包名称

时间:2014-12-31 07:20:34

标签: java wsdl

如何修改从多个wsdls生成的java类的包名称。我有两个wsdls,它们都生成类ObjectFactory,package-info等类,具有完全相同的包名。因此,我无法在我的代码中组织导入。对于wsdls,我的包看起来像这样 -

WSDL A
    com.test.customerinfo.dto
    com.test.customerinfo.exceptions
    com.test.customerinfo.service

WSDL B    
    com.test.customerinfo.dto
    com.test.customerinfo.exceptions
    com.test.customerinfo.service

我希望它看起来像这样 -

WSDL A
    com.test.customerinfo.dto
    com.test.customerinfo.exceptions
    com.test.customerinfo.service

WSDL B    
    com.testOne.customerinfo.dto
    com.testOne.customerinfo.exceptions
    com.testOne.customerinfo.service

我试过这个,但它没有用 -

<plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-codegen-plugin</artifactId>
    <version>2.7.7</version>
    <executions>
       <execution>
          <id>generate-sources</id>
          <phase>generate-sources</phase>
          <configuration>
             <sourceRoot>target/generated-sources/test/java</sourceRoot>
             <wsdlOptions>
                <wsdlOption>
                   <wsdl>src/main/resources/wsdl/test/GetInfo.wsdl</wsdl>
                   <extraargs>
                      <extraarg>-server</extraarg>
                      <extraarg>-client</extraarg>
                      <extraarg>-impl</extraarg>
                      <extraarg>-verbose</extraarg>
                      <extraarg>-p</extraarg>
                      <extraarg>http://dto.customerinfo.test.com/=com.test.customerinfo.dto</extraarg>
                      <extraarg>-p</extraarg>
                      <extraarg>http://services.customerinfo.test.com/=com.test.customerinfo.services</extraarg>
                      <extraarg>-p</extraarg>
                      <extraarg>http://exceptions.customerinfo.test.com/=com.test.customerinfo.exceptions</extraarg>
                   </extraargs>
                   <frontEnd>jaxws21</frontEnd>
                   <faultSerialVersionUID>1</faultSerialVersionUID>
                </wsdlOption>
             </wsdlOptions>
          </configuration>
          <goals>
             <goal>wsdl2java</goal>
          </goals>
       </execution>
    </executions>
 </plugin>

请告知。

1 个答案:

答案 0 :(得分:8)

cxf-codgen-plugin中,您可以在wsdlOptions部分指定包裹映射:

<plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-codegen-plugin</artifactId>
    <version>${cxf.version}</version>
    <executions>
        <execution>
            ...
            <configuration>
                ...
                <wsdlOptions>
                    <wsdlOption>
                        ...
                        <packagenames>
                        <!-- Package Mappings -->
                            <packagename>http://namespace.example.com/=com.test.package</packagename>
                        </packagenames>
                        ...
                    </wsdlOption>
                </wsdlOptions>
            </configuration>
            <goals>
                <goal>wsdl2java</goal>
            </goals>
        </execution>
    </executions>
</plugin>

或者您也可以使用extraarg

<wsdlOptions>
    <wsdlOption>
        ...
        <extraargs>
            <extraarg>-p</extraarg>
            <extraarg>http://namespace.example.com/=com.test.package</extraarg>
        </extraargs>
    </wsdlOption>
</wsdlOptions>