我是 Ant 新手,遇到 java.lang.ClassNotFoundException。当从 eclipse / Ant build.xml 运行我的 Junit 时,但是,当我从 eclipse 本身运行我的单元测试时,我的测试通过没有问题。我的类路径应该有问题,我无法弄清楚。
我的环境是:
Java_home: C:/Program Files/Java/jdk1.7.0_25 Ant_home: C:/Users/Armen/javaFolder/apache-ant-1.9.2/bin JUnit_home: C:/Users/Armen/javaFolder/apache-ant-1.9 .2/bin/junit-4.10.jar
我的构建.xml
<property name="junitLocation">C:/Users/Armen/javaFolder/apache-ant-1.9.2/bin/junit-4.10.jar</property>
<property name="antLocation2">C:/Users/Armen/JavaFolder/apache-ant-1.9.2.jar</property>
<property name="testCode">C:/Users/Armen/workspace/MockingObjects/test/demo</property>
<property name="srcCode">C:/Users/Armen/workspace/MockingObjects/src/demo</property>
<target name="compile" depends="clean">
<javac includeantruntime="false" srcdir="./src" destdir="./staging" ></javac>
</target>
<target name="run" depends="compile, unitTest">
<java classname="demo.AccountService"><classpath path="./staging"></classpath></java>
</target>
<target name="unitTest" depends="compile">
<junit printsummary="true" showoutput="true" haltonfailure="false" fork="yes">
<formatter type="plain" usefile="true"/>
<test name="demo.TestAccountService" outfile="./result" ></test>
<classpath>
<pathelement location="${junitLocation}"/>
<pathelement location="${antLocation}"/>
<pathelement location="${testCode}" />
<pathelement location="${srcCode}"/>
</classpath>
</junit>
</target>
<target name="clean">
<delete dir="staging"></delete>
<mkdir dir="./staging"/>
</target>
在此处输入图像描述