title: Trouble with Apache Ant Tutorial - JUnit
body: <p>I'm trying to following apache's ANT tutorial:</p>
  
  <p><a href="http://ant.apache.org/manual/index.html" rel="nofollow">http://ant.apache.org/manual/index.html</a></p>
  
  <p>I'm currently at the JUnit portion, but I keep getting errors related to not being able to find the junit.framework package.</p>
  
  <p>I believe I've followed the tutorial exactly as follows - Here are the details:</p>
  
  <p>-----My file structure-----</p>
  
  <pre><code>build.xml
  /build
  ../classes
  /lib
  ..log4j-1.2.8.jar
  myManifest
  /src
  ..HelloWorldTest.java
  ..log4j.properties
  ../oata
  ....HelloWorld.java
  </code></pre>
  
  <p>-----Sources-----</p>
  
  <p>myManifest:</p>
  
  <pre><code>Main-Class: oata.HelloWorld
  </code></pre>
  
  <p>build.xml:</p>
  
  <pre><code>&lt;project name ="HelloWorld" basedir="." default="main"&gt;
      &lt;property name="src.dir" value="src" /&gt;
      &lt;property name="build.dir" value="build" /&gt;
      &lt;property name="classes.dir" value="${build.dir}/classes" /&gt;
      &lt;property name="jar.dir"    value="${build.dir}/jar" /&gt;
      &lt;property name="lib.dir"    value="lib" /&gt;
  
      &lt;path id="classpath"&gt;
          &lt;fileset dir="${lib.dir}" includes="**/*.jar" /&gt;
      &lt;/path&gt;
  
      &lt;property name="main-class" value="oata.HelloWorld" /&gt;
  
      &lt;target name="clean"&gt;
          &lt;delete dir="${build.dir}"/&gt;
      &lt;/target&gt;
  
      &lt;target name="compile"&gt;
          &lt;mkdir dir="${classes.dir}"/&gt;
          &lt;javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath" /&gt;
          &lt;copy todir="${classes.dir}" &gt;
              &lt;fileset dir="${src.dir}" excludes="**/*.java" /&gt;
          &lt;/copy&gt;
      &lt;/target&gt;
  
      &lt;target name="jar" depends="compile"&gt;
          &lt;mkdir dir="${jar.dir}" /&gt;
          &lt;jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}"&gt;
              &lt;manifest&gt;
                  &lt;attribute name="Main-Class" value="${main-class}" /&gt;
              &lt;/manifest&gt;
          &lt;/jar&gt;
      &lt;/target&gt;
  
      &lt;target name="run" depends="jar"&gt;
          &lt;java fork="true" classname="${main-class}"&gt;
              &lt;classpath&gt;
                  &lt;path refid="classpath"/&gt;
              &lt;path id="application" location="${jar.dir}/${ant.project.name}.jar"/&gt;
              &lt;/classpath&gt;
          &lt;/java&gt;
      &lt;/target&gt;
  
      &lt;target name="junit" depends="jar"&gt;
              &lt;junit printsummary="yes"&gt;
                  &lt;classpath&gt;
                      &lt;path refid="classpath"/&gt;
                      &lt;path refid="application"/&gt;
                  &lt;/classpath&gt;
  
                  &lt;batchtest fork="yes"&gt;
                      &lt;fileset dir="${src.dir}" includes="*Test.java"/&gt;
                  &lt;/batchtest&gt;
              &lt;/junit&gt;
          &lt;/target&gt;
  
      &lt;target name="clean-build" depends="clean,jar" /&gt;
  
      &lt;target name="main" depends="clean,run" /&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>HelloWorldTest.java:</p>
  
  <pre><code>public class HelloWorldTest extends junit.framework.TestCase {
  
      public void testNothing() {
      }
  
      public void testWillAlwaysFail() {
          fail("An error message");
      }
  
  }
  </code></pre>
  
  <p>HelloWorld.java</p>
  
  <pre><code>package oata;
  
  import org.apache.log4j.Logger;
  
  public class HelloWorld {
      static Logger logger = Logger.getLogger(HelloWorld.class);
  
      public static void main(String [] args){
          logger.info("Hello World!");
      }
  }
  </code></pre>
  
  <p>log4j.properties:</p>
  
  <pre><code>log4j.rootLogger=DEBUG, stdout
  
  log4j.appender.stdout=org.apache.log4j.ConsoleAppender
  log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
  log4j.appender.stdout.layout.ConversionPattern=%m%n
  </code></pre>
  
  <p>---Output---</p>
  
  <pre><code> ant -verbose junit
  Apache Ant(TM) version 1.8.2 compiled on June 20 2012
  Trying the default build file: build.xml
  Buildfile: /Users/jtyler/Projects/AntHelloWorld/build.xml
  Detected Java version: 1.6 in: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
  Detected OS: Mac OS X
  parsing buildfile /Users/jtyler/Projects/AntHelloWorld/build.xml with URI = file:/Users/jtyler/Projects/AntHelloWorld/build.xml
  Project base dir set to: /Users/jtyler/Projects/AntHelloWorld
  parsing buildfile jar:file:/usr/share/ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml with URI = jar:file:/usr/share/ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
  Build sequence for target(s) `junit' is [compile, jar, junit]
  Complete build sequence is [compile, jar, junit, clean, run, main, clean-build, ]
  
  compile:
      [mkdir] Skipping /Users/jtyler/Projects/AntHelloWorld/build/classes because it already exists.
      [javac] /Users/jtyler/Projects/AntHelloWorld/build.xml:20: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
      [javac] HelloWorldTest.java added as HelloWorldTest.class doesn't exist.
      [javac] /Users/jtyler/Projects/AntHelloWorld/src/log4j.properties skipped - don't know how to handle it
      [javac] oata/HelloWorld.java added as oata/HelloWorld.class doesn't exist.
      [javac] Compiling 2 source files to /Users/jtyler/Projects/AntHelloWorld/build/classes
      [javac] Using modern compiler
      [javac] Compilation arguments:
      [javac] '-d'
      [javac] '/Users/jtyler/Projects/AntHelloWorld/build/classes'
      [javac] '-classpath'
      [javac] '/Users/jtyler/Projects/AntHelloWorld/build/classes:/Users/jtyler/Projects/AntHelloWorld/lib/log4j-1.2.8.jar:/usr/share/ant/lib/ant-launcher.jar:/usr/share/ant/lib/ant-antlr.jar:/usr/share/ant/lib/ant-jmf.jar:/usr/share/ant/lib/ant-junit.jar:/usr/share/ant/lib/ant-junit4.jar:/usr/share/ant/lib/ant-swing.jar:/usr/share/ant/lib/ant-testutil.jar:/usr/share/ant/lib/ant.jar'
      [javac] '-sourcepath'
      [javac] '/Users/jtyler/Projects/AntHelloWorld/src'
      [javac] '-g:none'
      [javac] 
      [javac] The ' characters around the executable and arguments are
      [javac] not part of the command.
      [javac] Files to be compiled:
      [javac]     /Users/jtyler/Projects/AntHelloWorld/src/HelloWorldTest.java
      [javac]     /Users/jtyler/Projects/AntHelloWorld/src/oata/HelloWorld.java
      [javac] /Users/jtyler/Projects/AntHelloWorld/src/HelloWorldTest.java:1: package junit.framework does not exist
      [javac] public class HelloWorldTest extends junit.framework.TestCase {
      [javac]                                                    ^
      [javac] /Users/jtyler/Projects/AntHelloWorld/src/HelloWorldTest.java:7: cannot find symbol
      [javac] symbol  : method fail(java.lang.String)
      [javac] location: class HelloWorldTest
      [javac]         fail("An error message");
      [javac]         ^
      [javac] 2 errors
  
  BUILD FAILED
  /Users/jtyler/Projects/AntHelloWorld/build.xml:20: Compile failed; see the compiler error output for details.
      at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:1150)
      at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:912)
      at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
      at org.apache.tools.ant.Task.perform(Task.java:348)
      at org.apache.tools.ant.Target.execute(Target.java:390)
      at org.apache.tools.ant.Target.performTasks(Target.java:411)
      at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
      at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
      at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
      at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
      at org.apache.tools.ant.Main.runBuild(Main.java:809)
      at org.apache.tools.ant.Main.startAnt(Main.java:217)
      at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
      at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
  
  Total time: 0 seconds
  </code></pre>
  
  <p>Is there something I'm missing that's needed to be included that was (or wasn't) mentioned in the tutorial?</p>
  
  <p><strong>EDIT</strong>: Based on Alex's inquiries, I tested to see if I had ant's junit jars in my shared directories (which I do):</p>
  
  <pre><code>$ ls /usr/share/ant/lib/ant-junit*.jar
  /usr/share/ant/lib/ant-junit.jar    /usr/share/ant/lib/ant-junit4.jar
  </code></pre>
  
  <p>I also tried to manually put ant-junit, ant-junit4.jar, and junit.jar into my project's lib directory, with the following results (all errors) after running <strong>ant clean junit</strong>:</p>
  
  <ul>
  <li>junit.jar - /Users/jtyler/Projects/AntHelloWorld/build.xml:45: Reference application not found.</li>
  <li>ant-junit.jar: package junit.framework does not exist  </li>
  <li>ant-junit.jar and ant.junit4.jar: package junit.framework does not exist</li>
  <li>ant-junit4.jar: package junit.framework does not exist</li>
  </ul>
  
  <p><strong>EDIT</strong> The whole error when only junit.jar is included in the lib folder and calling <strong>ant clean junit</strong> is:</p>
  
  <pre><code>$ ant clean junit
  Buildfile: /Users/jtyler/Projects/AntHelloWorld/build.xml
  
  clean:
     [delete] Deleting directory /Users/jtyler/Projects/AntHelloWorld/build
  
  compile:
      [mkdir] Created dir: /Users/jtyler/Projects/AntHelloWorld/build/classes
      [javac] /Users/jtyler/Projects/AntHelloWorld/build.xml:20: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
      [javac] Compiling 2 source files to /Users/jtyler/Projects/AntHelloWorld/build/classes
       [copy] Copying 1 file to /Users/jtyler/Projects/AntHelloWorld/build/classes
  
  jar:
      [mkdir] Created dir: /Users/jtyler/Projects/AntHelloWorld/build/jar
        [jar] Building jar: /Users/jtyler/Projects/AntHelloWorld/build/jar/HelloWorld.jar
  
  junit:
  
  BUILD FAILED
  /Users/jtyler/Projects/AntHelloWorld/build.xml:45: Reference application not found.
  </code></pre>