title: Running JUnit from Apache Ant with included jar file results in "JUnitTask was not found"
body: <p>I am using Apache Ant to compile and run JUnit tests. At the moment, it is working on environments where the ant JUnit library is installed as a part of Ant, but not on other environments. I want to fix this. I have tried including the jars needed(<code>junit-4.12.jar</code> and <code>hamcrest-core-1.3.jar</code>, if I understand it correctly) but it is not working. The relevant part of my <code>build.xml</code> is as follows:</p>
  
  <pre><code>  &lt;property name="build.path" location="build/src"/&gt;
    &lt;property name="build.test.path" location="build/test"/&gt;
    &lt;property name="lib.path.rel" value="lib"/&gt;
    &lt;property name="junit.file" value="${lib.path.rel}/junit/junit-4.12.jar"/&gt;
    &lt;property name="hamcrest.file" value="${lib.path.rel}/junit/hamcrest-core-1.3.jar"/&gt;
  
    &lt;path id="junit.class.path"&gt;
      &lt;pathelement location="${junit.file}"/&gt;
      &lt;pathelement location="${hamcrest.file}"/&gt;
      &lt;pathelement location="${build.path}"/&gt;
    &lt;/path&gt;
  
    &lt;target name="test-compile" depends="test-clean"&gt;
      &lt;mkdir dir="${build.test.path}"/&gt;
  
      &lt;javac srcdir="${test.path}"
             destdir="${build.test.path}"
             includeantruntime="false"&gt;
        &lt;classpath refid="junit.class.path" /&gt;
      &lt;/javac&gt;
    &lt;/target&gt;
  
    &lt;target name="test" depends="test-compile"&gt;
      &lt;junit&gt;
        &lt;classpath&gt;
          &lt;path refid="junit.class.path"/&gt;
          &lt;pathelement location="${build.test.path}"/&gt;
        &lt;/classpath&gt;
        &lt;batchtest&gt;
          &lt;fileset dir="${build.test.path}"&gt;
            &lt;include name="**/*Test*"/&gt;
          &lt;/fileset&gt;
        &lt;/batchtest&gt;
        &lt;formatter type="brief" usefile="false"/&gt;
      &lt;/junit&gt;
    &lt;/target&gt;
  </code></pre>
  
  <p>The task <code>test-compile</code> successfully builds the tests.<br/>
  The task <code>test</code>, however, results in the following error:<br/>
  <code>Problem: failed to create task or type junit
  Cause: the class org.apache.tools.ant.taskdefs.optional.junit.JUnitTask was not found.</code><br/><br/>
  I am using CentOS 7 with Ant 1.9.2, and though I think it is reasonable to request users to update Ant to the latest version available, I have no control over what OS and libraries they have installed. As such, I want to solve the problem not by <code>yum install something</code> or whatnot, but by finding a way to properly use the JUnit jar files(if that is possible). Then, when they pull the git repository and run the task, it will work on any OS or environment(since they will be using a jar file they just pulled). Obviously, this also means that "just put the jars in the Ant lib dir" will not be a viable solution.<br/>
  Thank you.</p>