title: another java.lang.ClassNotFoundException in ant's junit task
body: <p>I can't figure out why I am getting this exception from my ant build.xml file. I checked and everything is in the classpath. Why must this be so complicated?!</p>
  
  <p>I had trouble with Ant in the past and it seems it always is something related to the classpath. I am pointing to junit.jar using both ways: within eclipse: window->preferences->ant->runtime->Ant Home->Add External Jars, and also within the build.xml script. This time Ant is not able to locate my test class in the junit task. Is there something wrong with the way I am pointing to this class?</p>
  
  <pre><code>&lt;target name="init"&gt;
      &lt;property name="sourceDir" value="src"/&gt;
      &lt;property name="outputDir" value="build" /&gt;
      &lt;property name="junitLocation" value="C:\...\org.junit4_4.3.1\junit.jar" /&gt; 
  &lt;/target&gt;
  
  &lt;target name="clean" depends="init"&gt;
      &lt;delete dir="${outputDir}" /&gt;
  &lt;/target&gt;
  
  &lt;target name="prepare" depends="clean"&gt;
      &lt;mkdir dir="${outputDir}" /&gt;
  &lt;/target&gt;
  
  &lt;target name="compile" depends="prepare"&gt;
       &lt;javac srcdir="${sourceDir}" destdir="${outputDir}" classpath="${junitLocation}"/&gt;
  &lt;/target&gt;
  
  &lt;path id="classpath"&gt;
     &lt;pathelement location="${outputDir}" /&gt;
     &lt;pathelement location="${junitLocation}" /&gt;
  &lt;/path&gt;
  
  &lt;target name="testApplication" depends="compile"&gt;
      &lt;echo&gt;Running the junit tests...&lt;/echo&gt;
      &lt;junit fork="yes" haltonfailure="yes"&gt;
          &lt;test name="my.package.MyTest" /&gt;
          &lt;formatter type="plain" usefile="false" /&gt;      
          &lt;classpath refid="classpath" /&gt;
      &lt;/junit&gt;
  &lt;/target&gt;
  </code></pre>
  
  <p>I am always getting:</p>
  
  <pre><code>    [junit] Testsuite: my.package.MyTest
      [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
      [junit]     Caused an ERROR
      [junit] my.package.MyTest
      [junit] java.lang.ClassNotFoundException: my.package.MyTest
      [junit]     at java.net.URLClassLoader$1.run(Unknown Source)
      [junit]     at java.security.AccessController.doPrivileged(Native Method)
      [junit]     at java.net.URLClassLoader.findClass(Unknown Source)
      [junit]     at java.lang.ClassLoader.loadClass(Unknown Source)
      [junit]     at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
      [junit]     at java.lang.ClassLoader.loadClass(Unknown Source)
      [junit]     at java.lang.ClassLoader.loadClassInternal(Unknown Source)
      [junit]     at java.lang.Class.forName0(Native Method)
      [junit]     at java.lang.Class.forName(Unknown Source)
  
  BUILD FAILED
  </code></pre>
  
  <p>Apparently, Ant finds junit.jar and attempts to start the test, but why can't it find my test class? I point to the folder with compiled test class. So I know that junit is on Ant's classpath at least, but the ClassNotFound puzzles me.</p>
  
  <p>Any ideas perhaps? Many thanks!</p>