title: Ant build error while running run target
body: <p>I am using ant  1.9.0 to run my Java project.i have a bat file which has command ant clean compile run.the clean and compile is working but for the target run I am getting below error</p>
  
  <pre><code> C:\Users\Susanta\MyMaven\MyMavenProject\build] on class org.apache.
   tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter: java.lang.NoClassDefFoundErrorjunit/framework/TestListener
  </code></pre>
  
  <p>I am attaching the build.xml please let me know the issue in my build.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="iso-8859-1"?&gt;
    &lt;!DOCTYPE project [
  ]&gt;
  
    &lt;project name="MyMavenProject" default="usage" basedir="."&gt;  
  
  &lt;!-- ========== Initialize Properties =================================== --&gt;
  &lt;property environment="env"/&gt;
  
  &lt;property name="ws.home" value="${basedir}"/&gt;
  &lt;property name="ws.jars" value="${user.home}/.m2/repository/"/&gt;
  &lt;property name="test.dest" value="${ws.home}/build"/&gt;
  &lt;property name="test.src" value="${ws.home}/src"/&gt;
  &lt;property name="test.reportsDir" value="${test.dest}/test_reports"/&gt;
  
  
  
  
  &lt;path id="testcase.path"&gt;
  
  
      &lt;pathelement location="${test.dest}"/&gt;
  
      &lt;fileset dir="${ws.jars}"&gt;
        &lt;include name="*.jar"/&gt;
      &lt;/fileset&gt;
  
    &lt;/path&gt;
  
  
  
  
  &lt;target name="setClassPath" unless="test.classpath"&gt;
      &lt;path id="classpath_jars"&gt;
          &lt;fileset dir="${ws.jars}" includes="**/*.jar"/&gt;
      &lt;/path&gt;
      &lt;pathconvert pathsep=":" 
          property="test.classpath" 
          refid="classpath_jars"/&gt;
  &lt;/target&gt;
  
  &lt;target name="init" depends="setClassPath"&gt;
      &lt;tstamp&gt;
          &lt;format property="start.time" pattern="MM/dd/yyyy hh:mm aa" /&gt;
      &lt;/tstamp&gt;
      &lt;condition property="ANT" 
          value="${env.ANT_HOME}/bin/ant.bat" 
          else="${env.ANT_HOME}/bin/ant"&gt;
                  &lt;os family="windows" /&gt;
      &lt;/condition&gt;
  
  &lt;/target&gt;
  
  &lt;!-- all --&gt;
  &lt;target name="all"&gt;
  &lt;/target&gt;
  
  &lt;!-- clean --&gt;
  &lt;target name="clean"&gt;
      &lt;delete dir="${test.dest}"/&gt;
  &lt;/target&gt;
  
  &lt;!-- compile --&gt;
  &lt;target name="compile" depends="init, clean" &gt; 
      &lt;delete includeemptydirs="true" quiet="true"&gt;
          &lt;fileset dir="${test.dest}" includes="**/*"/&gt;
      &lt;/delete&gt;
      &lt;echo message="making directory..."/&gt;
      &lt;mkdir dir="${test.dest}"/&gt;
      &lt;echo message="classpath------: ${test.classpath}"/&gt;
      &lt;echo message="compiling..."/&gt;
      &lt;javac 
          debug="true" 
          destdir="${test.dest}" 
          srcdir="${test.src}" 
          target="1.5" 
          classpath="${test.classpath}"
      &gt;
      &lt;/javac&gt;
    &lt;/target&gt;
  
  &lt;!-- build --&gt;
  &lt;target name="build" depends="init"&gt;
  &lt;/target&gt;
  
  
  
  
  &lt;target name="usage"&gt;
      &lt;echo&gt;
          ant run will execute the test
      &lt;/echo&gt;
  &lt;/target&gt;
  
  &lt;path id="test.run"&gt;
          &lt;fileset dir="${ws.jars}" includes="**/*.jar"/&gt;
  &lt;/path&gt;
  
  
  
  &lt;target name="run" &gt;  
      &lt;delete includeemptydirs="true" quiet="true"&gt;
                  &lt;fileset dir="${test.reportsDir}" includes="**/*"/&gt;
              &lt;/delete&gt;
              &lt;java jar="${ws.jars}" fork="true" spawn="true" /&gt;  
              &lt;junit fork="yes" haltonfailure="no" printsummary="yes"&gt;
                  &lt;classpath refid="test.run" /&gt;  
  
                &lt;!--  &lt;classpath ="${test.classpath}"/&gt; --&gt;  
              &lt;batchtest  todir="${test.reportsDir}" fork="true"&gt;  
              &lt;fileset dir="${test.dest}"&gt;  
  
            &lt;!--include name="tests/LoginTest.class" /&gt;
           &lt;include name="tests/Parameterized_Test.class" /&gt;
           &lt;include name="tests/TestApplication.class" /--&gt;
            &lt;include name="com/testing/GoogleTest.class" /&gt;
            &lt;include name="com/testing/YahooTest.class" /&gt;
  
  
  
  
  
              &lt;/fileset&gt;  
              &lt;/batchtest&gt;    
                  &lt;formatter type="xml" /&gt;  
                  &lt;classpath refid="testcase.path" /&gt;  
          &lt;/junit&gt;  
              &lt;junitreport todir="${test.reportsDir}"&gt;    
                  &lt;fileset dir="${test.reportsDir}"&gt;  
                      &lt;include name="TEST-*.xml" /&gt;  
                  &lt;/fileset&gt;  
                  &lt;report todir="${test.reportsDir}" /&gt;  
              &lt;/junitreport&gt;  
          &lt;/target&gt;
  </code></pre>
  
  <p></p>
  
  <p>below is the error:</p>
  
  <pre><code>   C:\Users\Susanta\MyMaven\MyMavenProject\build] on class org.apache.
    tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter: java.lang.NoClassDefF
   oundError: junit/framework/TestListener
   [exec]     at java.lang.ClassLoader.defineClass1(Native Method)
   [exec]     at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
   [exec]     at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
   [exec]     at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
   [exec]     at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
   [exec]     at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
   [exec]     at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
   [exec]     at java.security.AccessController.doPrivileged(Native Method)
   [exec]     at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
   [exec]     at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
   [exec]     at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
   [exec]     at org.apache.tools.ant.AntClassLoader.findBaseClass(AntClassLoader.java:1385)
   [exec]     at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoaderjava:1064)
   [exec]     at org.apache.tools.ant.util.SplitClassLoader.loadClass(SplitClassLoader.java:58)
   [exec]     at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
   [exec]     at java.lang.ClassLoader.defineClass1(Native Method)
   [exec]     at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
   [exec]     at org.apache.tools.ant.AntClassLoader.defineClassFromData(AntClassLoader.java:1128)
   [exec]     at org.apache.tools.ant.AntClassLoader.getClassFromStream(AntClassLoader.java:1299)
   [exec]     at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1354)
   [exec]     at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoaderjava:1315)
   [exec]     at org.apache.tools.ant.util.SplitClassLoader.loadClass(SplitClassLoader.java:52)
   [exec]     at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
   [exec]     at java.lang.Class.forName0(Native Method)
   [exec]     at java.lang.Class.forName(Class.java:266)
   [exec]     at 
  
     org.apache.tools.ant.taskdefs.optional.junit.FormatterElement.createFormatter(FormatterElement.java:286)
   [exec]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.logVmExit(JUnitTask.java:1653)
   [exec]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.logVmCrash(JUnitTask.java:1617)
   [exec]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeAsForked(JUnitTask.java:1099)
   [exec]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:851)
   [exec]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeOrQueue(JUnitTask.java:1899)
   [exec]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:800)
   [exec]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
   [exec]     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
   [exec]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   [exec]     at java.lang.reflect.Method.invoke(Method.java:601)
   [exec]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
   [exec]     at org.apache.tools.ant.Task.perform(Task.java:348)
   [exec]     at org.apache.tools.ant.Target.execute(Target.java:435)
   [exec]     at org.apache.tools.ant.Target.performTasks(Target.java:456)
   [exec]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
   [exec]     at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
  
   [exec]     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
   [exec]     at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
   [exec]     at org.apache.tools.ant.Main.runBuild(Main.java:851)
   [exec]     at org.apache.tools.ant.Main.startAnt(Main.java:235)
   [exec]     at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
   [exec]     at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
   [exec] Caused by: java.lang.ClassNotFoundException: junit.framework.TestListener
   [exec]     at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
   [exec]     at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
   [exec]     at java.security.AccessController.doPrivileged(Native Method)
   [exec]     at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
   [exec]     at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
   [exec]     at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
   [exec]     ... 48 more
   [exec]
   [exec] Total time: 7 seconds
  [INFO] ------------------------------------------------------------------------
  [INFO] BUILD FAILURE
  [INFO] ------------------------------------------------------------------------
  [INFO] Total time: 10.773s
  [INFO] Finished at: Mon Jul 07 03:01:39 IST 2014
  [INFO] Final Memory: 7M/18M
  [INFO] ------------------------------------------------------------------------
  [ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:
  run (default) on project MyMavenProject: An Ant BuildException has occured: exec
   returned: 1
  [ERROR] around Ant part ...&lt;exec dir="C:\Users\Susanta\MyMaven\MyMavenProject" e
  xecutable="C:\Users\Susanta\MyMaven\MyMavenProject\testrunner.bat" failonerror="
  true"&gt;... @ 5:142 in C:\Users\Susanta\MyMaven\MyMavenProject\target\antrun\build
  -runtheapp.xml
  [ERROR] -&gt; [Help 1]
  org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal o
  rg.apache.maven.plugins:maven-antrun-plugin:1.7:run (default) on project MyMaven
  Project: An Ant BuildException has occured: exec returned: 1
  around Ant part ...&lt;exec dir="C:\Users\Susanta\MyMaven\MyMavenProject" executabl
  e="C:\Users\Susanta\MyMaven\MyMavenProject\testrunner.bat" failonerror="true"&gt;..
  . @ 5:142 in C:\Users\Susanta\MyMaven\MyMavenProject\target\antrun\build-runthea
  pp.xml
      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
      at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
      at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
      at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
      at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
      at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:317)
      at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152)
      at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)
      at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
      at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)
      at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
      at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
      at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
      at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
      Caused by: org.apache.maven.plugin.MojoExecutionException: An Ant BuildException
    has occured: exec returned: 1
   around Ant part ...&lt;exec dir="C:\Users\Susanta\MyMaven\MyMavenProject"    executable="C:\Users\Susanta\MyMaven\MyMavenProject\testrunner.bat" failonerror="true"&gt;..
  . @ 5:142 in C:\Users\Susanta\MyMaven\MyMavenProject\target\antrun\build-runtheapp.xml
  </code></pre>