Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify package names for java classes generated from wsdl

Tags:

java

wsdl

How do I modify package names for java classes generated from multiple wsdls. I have two wsdls, and both are generating classes like ObjectFactory, package-info etc with the exact same package name. As a result, I am not able to organize the imports in my code. My packages look like this for the 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

I want it to look something like this -

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

I tried this, but it didn't work -

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

Please advise.

like image 462
rickygrimes Avatar asked Dec 31 '14 07:12

rickygrimes


1 Answers

In cxf-codgen-plugin you can specify package mapping in the wsdlOptions section:

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

Or alternatively you can also use extraarg:

<wsdlOptions>
    <wsdlOption>
        ...
        <extraargs>
            <extraarg>-p</extraarg>
            <extraarg>http://namespace.example.com/=com.test.package</extraarg>
        </extraargs>
    </wsdlOption>
</wsdlOptions>
like image 198
Tobías Avatar answered Oct 21 '22 05:10

Tobías