java - 运行 ant build 得到 "package org.junit does not exist"

标签 java ant junit

当我使用 Java IDE 构建具有 JUnit 测试的项目(例如 NetBeans)时,它们编译正常,但是当我尝试在 IDE 之外使用 ant 运行构建脚本时,我收到错误“package org. junit 不存在”。

最佳答案

您应该将 junit.jar 添加到 ant 文件的类路径定义中。

有很多方法可以做到这一点,一个例子是:

<junit printsummary="yes" haltonfailure="yes">
    <classpath>
        <path refid="your.classpath.refid" />
        <fileset dir="${junit.dir}">
            <include name="**/junit.jar" />
        </fileset>
    </classpath>
    ...
</junit>

参见 Ant Manual有关设置类路径的详细信息。

关于java - 运行 ant build 得到 "package org.junit does not exist",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1792445/

相关文章:

java - Wildfly 10 中未找到无状态 Bean 中的 JNDI

java - 用于自定义对象的 Android 房间类型转换器

c++ - 无法构建 avahi4j : avahi4j_Client. c :18:32: fatal error: avahi-common/error. h: 没有这样的文件或目录

ant - 使用ivy在ant中构建 "fat jar",而不将jar复制到lib目录

java - 我应该在我的应用程序中声明 swing 组件为最终的吗?

junit - 如何在 JUnit 中强制 SQLException

java - ListView onitemclick

c++ - Ant -> 南特 -> Visual Studio 2005 构建

java - JUnit 示例程序编译但给出运行时错误

Java Stax Iterator API方法实现