如果不在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>

参考文献

  1. Ant jUnit任务
  2. 蚂蚁常见问题解答:junit忽略了我的类路径

翻译自: https://mkyong.com/ant/ant-error-must-include-junit-jar-if-not-in-ants-own-classpath/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值