2014-12-31 76 views
1

如何修改从多个wsdls生成的java类的包名称。我有两个wsdls,并且都使用完全相同的包名称生成像ObjectFactory,package-info等类。因此,我无法在我的代码中组织导入。我的包看起来像这样的WSDL文件 -修改从wsdl生成的java类的包名称

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> 

请指教。

+0

你如何生成从WSDL类?你使用哪种工具?例如,如果使用[CXF](http://cxf.apache.org/docs/wsdl-to-java.html),可以使用'-p [wsdl-namespace =] PackageName' –

+0

完成它我想要它在pom.xml中定义。你在这里给出的选项是命令行。 – rickygrimes

+0

你使用'cxf-codegen-plugin'吗? –

回答

6

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

让我试试这个。 – rickygrimes

+0

请注意'namespace'是可选的。在这里你可以找到一个完整的插件配置的例子:http://www.thetekblog.com/2014/01/cxf-codegen-plugin-maven-multiple-wsdl-in-different-packages/ –

+0

我看了命名空间wsdl,并试过这个,但它不起作用 - <! - Package Mappings - > http://services.abc.def.com/=com.test.services http://dto.abc.def.com/=com.test.dto http://exceptions.abc.def.com/=com.test.exceptions rickygrimes