title: Ant and Junit test java.lang.ClassNotFoundException
body: <p>I'm having a problem with an ant build.xml file that's giving me a java.lang.ClassNotFoundExcpetion.  I am able to run it fine on windows, but when I port it over to a Linux vm, I get the exception.  </p>
  
  <pre><code>&lt;project name="OBJECT" default="compile" &gt;
  &lt;!--
  Properties for the directories of .java
  These are the locations the the source files
  These are the locations of the .jar dependancy
   --&gt;
  &lt;property name="src.dir" location="src"/&gt;
  &lt;property name="src.java.dir" location="${src.dir}/csc439"/&gt;
  &lt;property name="src.test.dir" location="${src.dir}/test"/&gt;
  &lt;property name="lib.dir" location="lib"/&gt;
  
  &lt;!--
  Properties for the directories of .class
  This gets deleted when ant clean is run
   --&gt;
  &lt;property name="target.dir" location="target"/&gt;
  &lt;property name="target.classes.java.dir" location="${target.dir}/classes/java"/&gt;
  &lt;property name="target.classes.test.dir" location="${target.dir}/classes/test"/&gt;
  
  &lt;!--Properties for the report directory--&gt;
  &lt;property name="target.report.dir" location="${target.dir}/report"/&gt;
  &lt;!-- 
  compile.java 
  Creates a directory for the .class files of the Java files for the file being tested
  Compiles the files and places the .class into the java file created
  Imports the necissary .jar files from the lib directory
  --&gt;
  &lt;target name="compile.java"&gt;
          &lt;mkdir dir="${target.classes.java.dir}"/&gt;
          &lt;javac includeantruntime="true" destdir="${target.classes.java.dir}"&gt;
              &lt;src path="${src.java.dir}"/&gt; 
              &lt;classpath&gt; 
                  &lt;pathelement location="${target.classes.java.dir}"/&gt;
                      &lt;pathelement location="${lib.dir}"/&gt;
                  &lt;fileset dir="${lib.dir}"&gt; 
                      &lt;include name="*.jar"/&gt;
                  &lt;/fileset&gt; 
              &lt;/classpath&gt; 
          &lt;/javac&gt;
      &lt;/target&gt;
  &lt;!-- 
  compile.test 
  Depends on compile.java to complete first
  Creates a directory for the .class files of the Test files
  Compiles the files and places the .class into the test file created
  --&gt;
  &lt;target name="compile.test" depends="compile.java"&gt;
      &lt;mkdir dir="${target.classes.test.dir}"/&gt;
      &lt;javac includeantruntime="true" destdir="${target.classes.test.dir}"&gt;
          &lt;src path="${src.test.dir}"/&gt;
          &lt;classpath&gt;
              &lt;pathelement location="${target.classes.java.dir}"/&gt;
                  &lt;pathelement location="${lib.dir}"/&gt;
              &lt;fileset dir="${lib.dir}"&gt; 
                  &lt;include name="*.jar"/&gt;
              &lt;/fileset&gt; 
          &lt;/classpath&gt;
      &lt;/javac&gt;
  &lt;/target&gt;
  &lt;!-- 
  compile
  This the the default
  Depends on compile.java, and compile.test
  --&gt;
  &lt;target name="compile" depends="compile.java,compile.test"/&gt;
  &lt;!-- 
  test
  Depends on compile
  Creates the report file
  Runs the JUnit test TestCacheSuite in the test file in the test .class directory
  --&gt; 
  &lt;target name="test" depends="compile"&gt;
      &lt;mkdir dir="${target.report.dir}"/&gt;
      &lt;junit printsummary="yes" haltonerror="yes" haltonfailure="yes" fork="yes"&gt;
          &lt;formatter type="plain" usefile="false"/&gt;
              &lt;formatter type="xml"/&gt;
          &lt;test name="test.TestMediaPlayer" todir="${target.report.dir}"/&gt;
          &lt;classpath&gt;
              &lt;pathelement location="${target.classes.java.dir}"/&gt;
              &lt;pathelement location="${target.classes.test.dir}"/&gt;
          &lt;/classpath&gt;
      &lt;/junit&gt;
  &lt;/target&gt;   
  &lt;!-- 
  report
  Depends on test
  Creates the file for html documents
  Depends on Test
  Creates a Junit report 
  --&gt; 
  &lt;target name="report" depends="test"&gt;
      &lt;mkdir dir="${target.report.dir}/html"/&gt;
      &lt;junitreport todir="${target.report.dir}"&gt;
          &lt;fileset dir="${target.report.dir}"&gt;
              &lt;include name="TEST-*.xml"/&gt;
          &lt;/fileset&gt;
          &lt;report todir="${target.report.dir}/html"/&gt;
      &lt;/junitreport&gt;
  &lt;/target&gt;
  &lt;!--
  clean
  Deletes the target directory
  This file contains all of the .class files
  This file contains all of the reports
  --&gt;
  &lt;target name = "clean"&gt;
      &lt;delete dir = "${target.dir}"/&gt;
  &lt;/target&gt;
  </code></pre>
  
  <p></p>
  
  <p>This is the error I get while running it on linux.</p>
  
  <pre><code>    [junit] Running test.MockObject
  [junit] Testsuite: test.MockObject
  [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
  [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
  [junit]
  [junit]     Caused an ERROR
  [junit] test.MockObject
  [junit] java.lang.ClassNotFoundException: test.MockObject
  [junit]     at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
  [junit]     at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
  [junit]     at java.security.AccessController.doPrivileged(Native Method)
  [junit]     at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
  [junit]     at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
  [junit]     at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
  [junit]     at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
  [junit]     at java.lang.Class.forName0(Native Method)
  [junit]     at java.lang.Class.forName(Class.java:264)
  [junit]
  </code></pre>
  
  <p>With the exact same build file I get it to run fine on windows. </p>
  
  <p>I have run it fine from command line on windows, as well as using Eclipse both work flawlessly. </p>
  
  <p>From everything that I read it says that I need to check the CLASSPATH, and PATH variables. 
  I have done this, but I must be doing something wrong.  I don't understand why with the same build information that it would run in one os, and not the other.  </p>
  
  <p>Any help would be greatly appreciated</p>