使用 JUnit 编译蚂蚁类路径问题

Compile with ant classpath issue with JUnit

我在使用 ant 时遇到编译问题,junit.jar 无法在此处找到我的构建文件:

<path id="lib">
    <fileset dir="library">
        <include name="*.jar" />
    </fileset>
</path>

<target name="test">
    <mkdir dir="tmp/reports" />

      <mkdir dir="tmp/build" />
        <javac srcdir="test" destdir="tmp/build" includeantruntime="false">
            <classpath refid="lib" />
        </javac>
        <echo message="Build done" />


    <junit fork="yes" haltonfailure="yes">

        <batchtest todir="tmp/reports">
            <fileset dir="tmp/test">
                <include name="*.java" />
            </fileset>
        </batchtest>
        <formatter type="xml" usefile="true"/>
        <classpath refid="test.classpath" />
    </junit>
</target>

我不确定我是否理解,因为 -verbose 模式下的 ant 确实找到了我的 JUnit jar 见附件截图:

这应该可以在 Ant 中正常编译。确保您使用的是最新版本的 JUnit。旧版本(例如 3.8.1)与 JUnit 4.x.

具有不同的包层次结构