我对JUnit和Ant还是个新手。我想知道这个错误是什么意思:
The <classpath> for <junit> must include junit.jar if not in Ant's own classpath我正在编译一个Java项目,我不能超越这一点。
发布于 2011-01-27 20:55:05
Junit ant任务的文档提供了如何将junit.jar放到类路径上的选项列表:
http://ant.apache.org/manual/Tasks/junit.html
为了节省查找时间,下面重现了这些选项。我更喜欢选项1。
发布于 2013-01-26 01:24:32
<property name="lib.dir" value="webcontent\WEB-INF\lib" />
<path id="classPath">
<pathelement location="${lib.dir}/junit-4.11.jar" />
</path>
<target name="test" depends="build">
<junit haltonerror="false" haltonfailure="false" fork="yes">
<classpath path="${lib.dir}">
<path refid="classPath" />
</classpath>
</junit>
</target>发布于 2015-01-04 08:28:10
今天我花了几个小时来解决这个问题。我已经在Eclipse中通过Project|Properties|Java Build Path指定了所有的.jar文件,但是仍然得到了
<classpath> for <junit> must include junit.jar if not in Ant's own classpath从Eclipse运行Ant时出错。
从命令行运行Ant可以很好地工作(我将所有内容都放在了类路径环境变量中)。
但在Eclipse中,唯一有效的方法是显式地声明元素中的类路径,例如:
<path id="JUnit 4.libraryclasspath">
<pathelement location="...\plugins\org.junit_4.11.0.v201303080030\junit.jar"/>
<pathelement location="...\plugins\org.hamcrest.core_1.3.0.v201303031735.jar"/>
<pathelement location="...\lib\ant-junit4.jar"/>
</path>
<path id="Ant1.classpath">
<pathelement location="bin"/>
<pathelement location="."/>
<path refid="JUnit 4.libraryclasspath"/>
</path>
... stuff...
<target name="test1" depends="compile">
<junit>
<classpath refid="Ant1.classpath"/>
</junit>
</target>如果不在junit元素中显式指定类路径,它每次都会在eclipse中中断,即使只是一个空的
<junit/> 参考文献
我不是专家,只是报告今天的工作。
-ctb
https://stackoverflow.com/questions/4809695
复制相似问题