Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Ant junit目标失败,因为ClassNotFoundException?_Java_Ant_Junit - Fatal编程技术网

Java Ant junit目标失败,因为ClassNotFoundException?

Java Ant junit目标失败,因为ClassNotFoundException?,java,ant,junit,Java,Ant,Junit,我想用ant运行JUnit测试。目前,我的build.xml中有以下内容: ... <property name="src.main.dir" location="src" /> <property name="src.test.dir" location="test" /> <property name="lib.dir" location="lib" /> <property name="build.dir" location="build" /&g

我想用ant运行JUnit测试。目前,我的build.xml中有以下内容:

...
<property name="src.main.dir" location="src" />
<property name="src.test.dir" location="test" />
<property name="lib.dir" location="lib" />
<property name="build.dir" location="build" />
<property name="reports.dir" location="reports" />
<property name="reports.tests.dir" location="${reports.dir}/tests" />
<property name="jar.dir" location="${build.dir}/jar" />
<property name="classes.dir" location="${build.dir}/classes" />
<property name="classes.main.dir" location="${classes.dir}/main" />
<property name="classes.test.dir" location="${classes.dir}/test" />

<target name="main" depends="test">
    <echo message="targets completed" />
</target>

<target name="test" depends="compile" >
    <junit printsummary="yes" haltonfailure="yes">
        <classpath>
            <path>
                <fileset dir="${lib.dir}">
                    <include name="hamcrest-core-1.3.jar" />
                    <include name="junit-4.12.jar" />
                </fileset>
            </path>
        </classpath>

        <formatter type="plain"/>

        <batchtest fork="yes" todir="${reports.tests.dir}">
            <fileset dir="${src.test.dir}">
                <include name="**/*Test.java" />
            </fileset>
        </batchtest>
    </junit>
</target>
...
        <formatter type="plain"/>

        <batchtest fork="yes" todir="${reports.tests.dir}">
            <fileset dir="${src.test.dir}">
                <include name="**/*Test.java" />
            </fileset>
        </batchtest>
    </junit>
</target>
您能告诉我为什么会出现异常,以及如何解决此问题吗

        <formatter type="plain"/>

        <batchtest fork="yes" todir="${reports.tests.dir}">
            <fileset dir="${src.test.dir}">
                <include name="**/*Test.java" />
            </fileset>
        </batchtest>
    </junit>
</target>
我的项目结构:
找到了错误。我忘了加上这些:

<pathelement path="${classes.test.dir}"/>
<pathelement path="${classes.main.dir}"/>
        <formatter type="plain"/>

        <batchtest fork="yes" todir="${reports.tests.dir}">
            <fileset dir="${src.test.dir}">
                <include name="**/*Test.java" />
            </fileset>
        </batchtest>
    </junit>
</target>

“测试”目标。现在,“测试”目标如下所示:

        <formatter type="plain"/>

        <batchtest fork="yes" todir="${reports.tests.dir}">
            <fileset dir="${src.test.dir}">
                <include name="**/*Test.java" />
            </fileset>
        </batchtest>
    </junit>
</target>


lib
目录中是否有较旧的
junit
版本?junit-4.12.jar和hamcrest-core-1.3.jar在/lib中