java - 神秘的 Ant 脚本

标签 java ant

我的 Ant 脚本有问题。我必须在 ant run 上运行 junit 测试。

我当前的脚本如下所示:

<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="doc" location="doc"/>
<property name="dist" location="dest"/>
<property name="lib" location="lib"/>
<property name="app" value="${ant.project.name}.jar"/>

<presetdef name="javac">
    <javac includeantruntime="false"/>
</presetdef>

<target name="clean">
    <delete dir="${build}"/>
    <delete dir="${dist}"/>
</target>

<target name="compile" depends="clean" description="Compile">
    <mkdir dir="${build}"/>
    <javac srcdir="${src}"
           destdir="${build}" 
           classpath="${lib}/junit-4.10.jar:${lib}/swing-layout-1.0.4.jar:${src}">
    </javac>
    <copy todir="${build}/checkers">
        <fileset dir="${lib}">
            <include name="resources/**" />
        </fileset>
    </copy>
</target>
<target name="run" depends="compile">
    <echo>Running the junit tests...</echo>
    <junit showoutput="no" fork="no">
        <classpath>
            <pathelement location="${build}"/>   
            <pathelement path="${build}:${lib}/junit-4.10.jar"/>
        </classpath>
        <formatter type="plain" usefile="false" />
        <test name="checkers.CheckersTest"/>
    </junit>
</target>

在我的 Linux 机器上测试运行良好,一切看起来都很好。但在我的 Windows 上,Ant 给了我很好的帮助:

java.lang.NoClassDefFoundError: junit/framework/TestListener

然而, Debug模式下的 Ant 告诉我,他从提供的 junit-4.10.jar 文件加载了 TestListener.class。

最佳答案

试试这个答案 http://youtrack.jetbrains.com/issue/TW-4882 :

To fix the problem you should either use fork="true" attribute for 
junit task (in this case classpath will be created correctly), or 
to copy junit.jar to ANT_HOME/lib (to ensure correct class loading). 

这也是这个错误 https://bugs.eclipse.org/bugs/show_bug.cgi?id=36198 。最后一条评论说 JUnit 可通过 org.eclipse.ant.optical.junit 片段在 Ant 中使用

关于java - 神秘的 Ant 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15890045/

相关文章:

performance - Jmeter-Ant xslt-report : BUILD FAILED Test. jtl 不存在错误,尽管我有 Test.jtl

java - 无法通过命令行或双击运行JAR

android - 如何包含 Material 设计库

junit - 如何使用 Ant 执行 JUnit 5 @Tag 测试?

javascript - Ant Regex 用文件内容替换模式

java - 如何在sybase 12数据库中存储BigInteger值?

java - Spring @JsonTest 不尊重 Jackson2ObjectMapperBuilderCustomizer 自定义 bean

java - 如何在 eclipse rcp 中管理 i18n 属性文件?

java - 为什么我在 Java 中得到 NoClassDefFoundError?

java - 行中的结果集输出将转换为以逗号分隔的单列输出