在Ant,Ivy和JUnit中找不到类-build.xml中的错误?

我正在尝试使用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>


LEATH
浏览 691回答 2
2回答

蝴蝶刀刀

我正在使用1.9.0。您确定没有在ant / lib或类似文件中安装junit jar吗?不知道我是否足够清楚地解释了我是否试图使其不起作用(根据我所链接的说明应该是可能的)。感谢您的更新-不确定它如何解决我的问题,但我想我可以尝试一下,如果可以,请慢慢减小它,直到回到问题为止。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java