javajunit4noclassdeffounderror

Executing JUnit tests in Ant build.xml - java.lang.NoClassDefFoundError


I am trying to run my JUnit tests using Ant build.xml but I am getting a java.lang.NoClassDefFoundError, how should I configure my build.xml file to make it work?

My Project Structure In Eclipse

apps/deploy/APP-INF/classes/test -> the compiled classes in are this path of my project folder

<target name="JUnitTest">
  <junit>
    <classpath>
      <pathelement path="apps/deploy/APP-INF/classes/test" />
      <pathelement location="apps/deploy/APP-INF/lib/junit.jar"/>
    </classpath>    
    <batchtest>
       <fileset dir="apps/deploy/APP-INF/src/test">
            <include name="**/*.java" />
       </fileset>
    </batchtest>
    <formatter type="brief" usefile="false"/>
  </junit>
</target>   

Console Log

My error is shown as above. Kindly appreciate any help!


Solution

  • Solved: The issue was having the wrong directory in fileset and name. I changed it to this:

    <batchtest>
        <fileset dir="${src.dir}/APP-INF/src">
            <include name="test/*.java"/>
        </fileset>
    </batchtest>