像这样在Ant中声明一个junit任务
build.xml
<!-- Run jUnit -->
<target name="junit" depends="resolve">
<junit printsummary="yes" haltonfailure="no">
<classpath refid="test.path" />
<classpath location="${build.dir}" />
<test name="com.mkyong.test.TestMessage"
haltonfailure="no" todir="${report.dir}" outfile="result">
<formatter type="plain" />
<formatter type="xml" />
</test>
</junit>
</target>
运行ant junit
,但遇到以下错误消息:
BUILD FAILED
build.xml:86: The <classpath> for <junit> must include junit.jar if not in Ant's own classpath
解
要在Ant中运行junit任务,请确保在类路径中定义了junit.jar
。
build.xml
<!-- Run jUnit -->
<target name="junit" depends="resolve">
<junit printsummary="yes" haltonfailure="no">
<classpath refid="test.path" />
<classpath location="${build.dir}" />
<!-- Make sure these two libraries are included -->
<classpath location="lib/junit-4.11.jar" />
<classpath location="lib/hamcrest-core-1.3.jar" />
<test name="com.mkyong.test.TestMessage"
haltonfailure="no" todir="${report.dir}" outfile="result">
<formatter type="plain" />
<formatter type="xml" />
</test>
</junit>
</target>
参考文献
翻译自: https://mkyong.com/ant/ant-error-must-include-junit-jar-if-not-in-ants-own-classpath/