TheJediCowboy
TheJediCowboy

Reputation: 9222

Classpath problem for my Ant Build file

I have been using this exact Build.xml file. I had problems in the beginning using the junit task with it, but I figured out those problems a couple months ago.

Recently I got the all to common error message when I ran my build file with the test task.

test:
[junit] Testsuite: com.mmz.mvc.test.AgentDAOTest
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit] Null Test:  Caused an ERROR
[junit] com.mmz.mvc.test.AgentDAOTest
[junit] java.lang.ClassNotFoundException: com.mmz.mvc.test.AgentDAOTest
[junit]     at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
[junit]     at java.lang.Class.forName0(Native Method)
[junit]     at java.lang.Class.forName(Class.java:247)
[junit]     at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
[junit]     at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
[junit]     at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)

BUILD FAILED
C:\Users\myName\Documents\Java\mmz\WEB-INF\build.xml:45: 
Testcom.mmz.mvc.test.AgentDAOTest failed

I know this problem is related to my classpath, but I am not sure why this would all of a sudden break when it has been working for so long.

My build follow looks like the following.

<property file="build.properties"/>
<property name="src.dir" value="src"/>
<property name="build.dir" value="classes"/>
<property name="web.dir" value="war"/>

 <path id="build.classpath">
  <fileset dir="lib">
      <include name="*.jar"/>
  </fileset>
  <fileset dir="${appserver.lib}">
      <include name="servlet*.jar"/>
  </fileset>
  <pathelement path="${build.dir}"/>
  <pathelement path="${test.dir}"/>
 </path>

 <path id="classpath.base"/>
 <path id="classpath.test">
 <pathelement location="c:/ant/lib/junit.jar" />
 <pathelement location="${build.dir}"/>
 <pathelement location="${src.dir}"/>
 <pathelement location="${test.dir}" />
 <pathelement location="classes"/>
 <path refid="classpath.base" />
 </path>

 <target name="build">
    <mkdir dir="${build.dir}"/>
     <mkdir dir="${test.dir}"/>
     <javac destdir="${build.dir}" source="1.5" target="1.5" debug="true"    deprecation="false" optimize="false" failonerror="true">
      <src path="${src.dir}"/>
       <classpath refid="build.classpath"/>
     </javac>
  <javac destdir="${build.dir}" source="1.5" target="1.5" debug="true" deprecation="false" optimize="false" failonerror="true">
      <src path="${test.dir}"/>
      <classpath refid="build.classpath"/>
  </javac>
  </target>

    <target name="test">
    <junit haltonfailure="true">
      <classpath refid="classpath.test" />
      <classpath refid="build.classpath"/>
      <formatter type="brief" usefile="false" />
      <test name="com.mmz.mvc.test.AgentDAOTest"/>
      <test name="com.mmz.mvc.test.AgentProfileDAOTest"/>
      <test name="com.mmz.mvc.test.BuyerDAOTest"/>
      <test name="com.mmz.mvc.test.BuyerSellerDAOTest"/>
      <test name="com.mmz.mvc.test.BaseDAOTest"/>
      <test name="com.mmz.mvc.test.MemberDAOTest"/>
      <test name="com.mmz.mvc.test.SellerDAOTest"/>
    </junit>

I am not very good with build files and I am not very good at understanding the how to setup classpaths and everything so If somebody could help I would appreciate it.

Upvotes: 2

Views: 3572

Answers (1)

Mark O&#39;Connor
Mark O&#39;Connor

Reputation: 77961

Looks like a missing jar file, containing the class "com.mmz.mvc.test.AgentDAOTest". Reading your build file suggests the jar used to be located in your "lib" directory.

I'm assuming, of course, that this class is not a missing Java source file located under you "src" or "${test.dir}" directories.....

Upvotes: 2

Related Questions