神秘的蚂蚁剧本

时间:2013-04-08 22:20:19

标签: java ant

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

我当前的脚本如下:

<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

调试模式下的Ant告诉我他从上面的junit-4.10.jar文件中加载了TestListener.class。

1 个答案:

答案 0 :(得分:2)

尝试这个答案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 is available in Ant via the org.eclipse.ant.optional.junit fragment