Here is an illustration of an ant script using nextMock to generate mock classes.

<project>

  <taskdef name="nextmock" classname="org.nextmock.ant.Task" 
            classpath="nextmock-ant-2.0.jar:lib/velocity-1.4.jar:lib/velocity-dep-1.4.jar:lib/log4j-1.2.11.jar"
  />

  <target name="compile">
     <javac srcdir="src/main/java" destdir="target/classes"/>
  </target>

  <target name="generate_test_sources" depends="compile">
     <nextmock destdir="target/test-generated/src">
        <configFiles dir="src/test/">
                                <include name="**/.nextmock"/>
                </configFiles>
                <classpath path="target/classes:target/test-classes"/>
     </nextmock>
  </target>
  
  <target name="compile_test" depends="generate_test_sources>
     <javac srcdir="target/test-generated/src" 
            destdir="target/test-classes"
            classpath="target/classes:lib/jmock-1.0.1.jar:lib/jmock-cglib-1.0.1.jar"/>
     <javac srcdir="src/test/java" 
            destdir="target/test-classes"
            classpath="target/classes:target/test-classes"/>
  </target>
  
  <target name="test" depends="compile_test">
     <junit printsummary="yes" haltonfailure="yes">
        <classpath>
           <pathelement path="target/classes:target/test-classes/:lib/jmock-1.0.1.jar:lib/jmock-cglib-1.0.1.jar:lib/cglib-2.1.jar"/>
        </classpath>
        <formatter type="plain"/>
        <batchtest fork="yes" todir="target/test-report">
           <fileset dir="src/test/java">
              <include name="**/*Test.java"/>
           </fileset>
        </batchtest>
     </junit>
  </target>
  
</project>

First you have to define the task nextMock. The execution of this task requires velocity and log4j. You have probably to adapt this classpath according to the location of those libraries.

Then comes the generation using the nextmock task.

The first parameter is the location where the generated code must be written.

Into the configFiles parameter, you must list your .nextmock configuration files. This configuration file is described here. It's a file containing the list of classes to mock.

The last parameter is the classpath where to look for classes to mock. It can be classes of you project (that must already be compiled) or classes coming from external library.

The next step in the build is to compile the test. That means compile the generated classes first then the test sources. To compile the generated classes, you need to place jmock and jmock-cglib into your classpath. The classes that you are mocking should also be accessible into the class path because the generated sources make references to them. You might also have to reference additional package if the class you mock are using Exceptions coming from some jars.

Finally you can run you unit test. For that, on top of you own dependencies, you need the jmock, jmock-cglib and cglib jars into your classpath.