简体   繁体   中英

Mysterious Ant script

I have problem with my Ant script. I have to run junit test on ant run .

My current script looks like:

<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>

On my Linux box test runs fine and everything looks good. But on my Windows, Ant gives my nice:

java.lang.NoClassDefFoundError: junit/framework/TestListener

Ant in debug mode however told me that he loaded TestListener.class from suplied junit-4.10.jar file.

Try this answer 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). 

Here is also bug for this https://bugs.eclipse.org/bugs/show_bug.cgi?id=36198 . Last comment says JUnit is available in Ant via the org.eclipse.ant.optional.junit fragment

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM