Defining Custom Properties

The Axis plug-in also generates a unit test for your web service, but this generated unit test needs to be customized. For example, the weather SOAP service requires a latitude and longitude to work properly, and the generated unit test uses an invalid value. You need to define a preGoal and postGoal on the axis:wsdl2java goal which copies the unit test to your src/test/java directory and excludes it from axis:compile. Because you don't want to overwrite your unit tests every time you run axis:wsdl2java, you need to define a custom property, generate.tests.

How do I do that?

Define a generate.tests property in your project.properties file which you will reference in your preGoal and postGoal. Add the following to project.properties:

# Custom properties
generate.tests = false

Now modify your preGoal and postGoal in maven.xml to use this new variable to overwrite unit tests only if generate.tests is set to true:

<preGoal name="axis:wsdl2java">
  <j:if test="${context.getVariable('generate.tests') =  = 'true'}">
  <ant:delete dir="${pom.build.unitTestSourceDirectory}/gov"/>
  </j:if>
</preGoal>
  
<postGoal name="axis:wsdl2java">
  <maven:get var="axis.test" plugin="maven-axis-plugin" 
      property="maven.axis.test.dir"/>
  
    <j:if test="${context.getVariable('generate.tests') =  = 'true'}">
      <ant:copy todir="${pom.build.unitTestSourceDirectory}">
        <fileset dir="${ axis.test }"/>
      </ant:copy>
    </j:if>
    <ant:delete dir="${maven.axis.test.dir}/gov"/>
</postGoal>

When you execute maven ...

Get Maven: A Developer's Notebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.