Share

October 8, 2008

Maven 2 AXIS WSDL Code Gen

Step 1:
Download the wsdls and put them in a dir i use "src/main/wsdl", this must match schemaDirectory

Step 2:
Add the following to the build pom.xml

<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>axistools-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>ax-ws-autogen</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                        <configuration>
                            <sourceDirectory>src/main/resources/wsdl</sourceDirectory>
                            <wsdlFiles>
                                <wsdlFile>Service1.wsdl</wsdlFile>
                                <wsdlFile>Service2.wsdl</wsdlFile>                             
                            </wsdlFiles>
                            <packageSpace>com.mycompany.servicename</packageSpace>
                            <testCases>false</testCases>
                            <serverSide>false</serverSide>
                            <subPackageByFileName>false</subPackageByFileName>
                            <outputDirectory>src/main/autogen</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
Step 3:
Add the autogen dir to the resources

<sourceDirectory>src/main/java</sourceDirectory>
  <resources>
      <resource>
          <directory>src/main/autogen</directory>
      </resource>
      <resource>
         <directory>src/main/resources</directory>
      </resource>
  </resources>

Step 4:
I tent do run mvn test to gen the source and run the unit test with the genrated sources

NOTES:
  • Don't check in autogen into source control
    After trial and error i learned not to check the auto gen code since you contal the changes to it by checked in the wsdl.
  • Exclude autogen code from code covrage using org.codehaus.mojo to do code covrage i tend to add the following plugin and exclude the auto gencode... so that the reports are clean
<plugin>
   <groupId>org.codehaus.mojo</groupId>
   <artifactId>cobertura-maven-plugin</artifactId>
      <executions>
        <execution>
           <goals>
             <goal>clean</goal>
            </goals>
        </execution>
      </executions>
      <configuration>
        <instrumentation>
           <excludes>
               <exclude>com/company/autogen/**/*.class</exclude>
           </excludes>
        </instrumentation>
      </configuration>
 </plugin>