Using Axis wsdl2java Ant task in a Maven 2 project

A Maven Axis Tools Plugin for Maven 2 in under development at Codehaus but it may not yet fit all your needs (as of may 2006). Here is a sample using Axis Ant tasks to perform a wsdl2java webservice creation. This sample performs both java code generation and web service declaration in Axis' configuration (server-config.wsdd).

Here are the tasks performed during the different Maven build cycle's phases :

  1. generate-source phase:

    1. Run wsdl2java

    2. Delete the generated service implementation class from the generated-source folder (ie /target/generated-source/main/java ) because it is already defined in the source folder (ie /src/main/java )

  2. process-classes phase:

    1. Deploy the generated webservice in Axis' configuration file (ie src/main/webapp/WEB-INF/server-config.wsdd). (!) Note that this task requires the code to be compiled ; this is the reason why it is called in the process-classes phase and not the generate-sources one

Extract of a Maven2 pom.xml:

<plugin>
  <artifactId>maven-antrun-plugin</artifactId>
  <executions>
    <execution>
      <id>wsdl2java</id>
      <phase>generate-sources</phase>
      <configuration>
        <tasks>
          <!-- create source folder -->
          <mkdir dir="target/generated-sources/main/java" />

          <!-- declare ant task -->
          <taskdef
            resource="axis-tasks.properties"
            classpathref="maven.compile.classpath" />

          <!-- run wsdl2java -->
          <axis-wsdl2java
            output="target/generated-sources/main/java"
            deployScope="Application" serverSide="true"
            testcase="true" url="src/main/wsdl/helloWorld.wsdl" />
          
          <!--
          Delete server side implementation from /target/generated-sources/main/java/
          because this class is defined in /src/main/java
          -->
          <delete file="target/generated-sources/main/java/com/mycompany/ws/HelloWorldBindingImpl.java" />

        </tasks>
        
        <!--
        add "generated-sources" folders to the compile path
        -->
        <sourceRoot>target/generated-sources/main/java</sourceRoot>
        <testSourceRoot>target/generated-sources/test/java</testSourceRoot>

      </configuration>
      <goals>
        <goal>run</goal>
      </goals>
    </execution>

    <execution>
      <!--
      update axis' configuration file (server-config.wsdd) requires that the java 
      files are compiled thus, perform this task in the "process-classes" phase
      -->
      <id>Update server-config.wsdd</id>
      <phase>process-classes</phase>
      <configuration>
        <tasks>
          <!-- update src/main/webapp/WEB-INF/server-config.wsdd -->
          <java
            classname="org.apache.axis.utils.Admin" fork="true"
            classpathref="maven.compile.classpath"
            dir="src/main/webapp/WEB-INF">
            <arg value="server" />
            <arg
              value="${basedir}/target/generated-sources/main/java/com/mycompany/ws/deploy.wsdd" />
          </java>
        </tasks>
      </configuration>
      <goals>
        <goal>run</goal>
      </goals>
    </execution>

  </executions>
</plugin>
...
<dependencies>
  <dependency>
    <groupId>org.apache.axis</groupId>
    <artifactId>axis</artifactId>
    <version>1.3</version>
  </dependency>
  <dependency>
    <groupId>org.apache.axis</groupId>
    <artifactId>axis-ant</artifactId>
    <version>1.3</version>
  </dependency>
</dependencies>

FrontPage/Axis/MavenIntegration (last edited 2009-09-20 22:47:22 by localhost)