title: Configuring ant to run unit tests. Where should libraries be? How should classpath be configured? avoiding ZipException
body: <p>I'm trying to run my junit tests using ant.  The tests are kicked off using a JUnit 4 test suite. If I run this direct from Eclipse the tests complete without error.  However if I run it from ant then many of the tests fail with this error repeated over and over until the junit task crashes.</p>
  
  <pre>
      [junit] java.util.zip.ZipException: error in opening zip file
      [junit]     at java.util.zip.ZipFile.open(Native Method)
      [junit]     at java.util.zip.ZipFile.(ZipFile.java:114)
      [junit]     at java.util.zip.ZipFile.(ZipFile.java:131)
      [junit]     at org.apache.tools.ant.AntClassLoader.getResourceURL(AntClassLoader.java:1028)
      [junit]     at org.apache.tools.ant.AntClassLoader$ResourceEnumeration.findNextResource(AntClassLoader.java:147)
      [junit]     at org.apache.tools.ant.AntClassLoader$ResourceEnumeration.nextElement(AntClassLoader.java:130)
      [junit]     at org.apache.tools.ant.util.CollectionUtils$CompoundEnumeration.nextElement(CollectionUtils.java:198)
      [junit]     at sun.misc.CompoundEnumeration.nextElement(CompoundEnumeration.java:43)
      [junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.checkForkedPath(JUnitTask.java:1128)
      [junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeAsForked(JUnitTask.java:1013)
      [junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:834)
      [junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeOrQueue(JUnitTask.java:1785)
      [junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:785)
      [junit]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
      [junit]     at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
      [junit]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      [junit]     at java.lang.reflect.Method.invoke(Method.java:597)
      [junit]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
      [junit]     at org.apache.tools.ant.Task.perform(Task.java:348)
      [junit]     at org.apache.tools.ant.Target.execute(Target.java:357)
      [junit]     at org.apache.tools.ant.Target.performTasks(Target.java:385)
      [junit]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
      [junit]     at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
      [junit]     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
      [junit]     at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
      [junit]     at org.apache.tools.ant.Main.runBuild(Main.java:758)
      [junit]     at org.apache.tools.ant.Main.startAnt(Main.java:217)
      [junit]     at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
      [junit]     at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
  
  </pre>
  
  <p>my test running task is as follows:</p>
  
  <pre>
      &lt;target name=&quot;run-junit-tests&quot; depends=&quot;compile-tests,clean-results&quot;&gt;
          &lt;mkdir dir=&quot;${test.results.dir}&quot;/&gt;
          &lt;junit failureproperty=&quot;tests.failed&quot; fork=&quot;true&quot; showoutput=&quot;yes&quot; includeantruntime=&quot;false&quot;&gt;
              &lt;classpath refid=&quot;test.run.path&quot; /&gt;
              &lt;formatter type=&quot;xml&quot; /&gt;
              &lt;test name=&quot;project.AllTests&quot; todir=&quot;${basedir}/test-results&quot; /&gt;
          &lt;/junit&gt;
          &lt;fail if=&quot;tests.failed&quot; message=&quot;Unit tests failed&quot;/&gt;
      &lt;/target&gt;
  </pre>
  
  <p>I've verified that the classpath contains the following as well as all of the program code and libraries:</p>
  
  <pre>
  ant-junit.jar
  ant-launcher.jar
  ant.jar
  easymock.jar
  easymockclassextension.jar
  junit-4.4.jar</pre>
  
  <p>I've tried debugging to find out which ZipFile it is trying to open with no luck, I've tried toggling <i>includeantruntime</i> and <i>fork</i> and i've tried running ant with <i>ant -lib test/libs</i> where test/libs contains the ant and junit libraries.</p>
  
  <p>Any info about what causes this exception or how you've configured ant to successfully run unit tests is gratefully received.</p>
  
  <p>ant 1.7.1 (ubuntu), java 1.6.0_10, junit 4.4</p>
  
  <p>Thanks.</p>
  
  <p><strong>Update - Fixed</strong>
  Found my problem. I had included my classes directory in my path using a fileset as opposed to a pathelement this was causing .class files to be opened as ZipFiles which of course threw an exception.</p>