Antの独自のクラスパスにjunit.jarが含まれていなければならない
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>