我正在嘗試使用Ant,Ivy和JUnit進行一個簡單的(?)測試項目。基本思想是Ivy將下載junit.jar,然后Ant將使用它。請注意,junit jar位于類路徑上,因為否則(classpath在junit任務中沒有元素),我會看到“ <junit>的<classpath>必須包含junit.jar(如果不在Ant自己的類路徑中)”。另外,下面給出的類(junit.framework.TestListener)在junit-4.8.2.jar中。但是,當我嘗試ant test以下操作時,我看到:test:BUILD FAILED/home/andrew/project/guice/hg/build.xml:33: java.lang.NoClassDefFoundError: junit/framework/TestListener at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:791)... at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280) at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)Caused by: java.lang.ClassNotFoundException: junit.framework.TestListener at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355)...所以我猜我的build.xml有問題嗎?什么?這是build.xml:<project xmlns:ivy="antlib:org.apache.ivy.ant" name="java-example" default="dist" basedir="."> <description> simple example build file </description> <property name="src" location="src"/> <property name="build" location="build"/> <property name="dist" location="dist"/> <property name="lib" location="lib"/> <path id="lib.path"> <fileset dir="${lib}"/> </path> <target name="init"> <tstamp/> <mkdir dir="${build}"/> </target> <target name="compile" depends="init,resolve" description="compile the source"> <javac srcdir="${src}" destdir="${build}" classpathref="lib.path" includeantruntime="false"> <compilerarg value="-Xlint"/> </javac> </target> <target name="test" depends="compile" description="run the tests"> <junit> <classpath refid="lib.path"/> <batchtest> <fileset dir="${build}"> <include name="**/*Test.class"/> </fileset> </batchtest> </junit> </target>
2 回答

蝴蝶刀刀
TA貢獻1801條經驗 獲得超8個贊
我正在使用1.9.0。您確定沒有在ant / lib或類似文件中安裝junit jar嗎?不知道我是否足夠清楚地解釋了我是否試圖使其不起作用(根據我所鏈接的說明應該是可能的)。感謝您的更新-不確定它如何解決我的問題,但我想我可以嘗試一下,如果可以,請慢慢減小它,直到回到問題為止。
添加回答
舉報
0/150
提交
取消