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 JUnit Ant类NotFoundException_Java_Ant_Junit_Classpath_Build.xml - Fatal编程技术网

Java JUnit Ant类NotFoundException

Java JUnit Ant类NotFoundException,java,ant,junit,classpath,build.xml,Java,Ant,Junit,Classpath,Build.xml,当我运行我的目标TranslatorWorkflow时,我得到了一个java.lang.ClassNotFoundException,它应该执行JUnit测试。我正在运行一个build.xml文件,目标是:buildtranslatorworkflow。它可以编译,但在JUnit测试中立即失败。 我的TranslatorWorkflow.class文件位于{basedir}/bin/testScripts/中。我的类路径和目标是: 类路径: <path id="classpath">

当我运行我的目标
TranslatorWorkflow
时,我得到了一个
java.lang.ClassNotFoundException
,它应该执行JUnit测试。我正在运行一个
build.xml
文件,目标是:
buildtranslatorworkflow
。它可以编译,但在JUnit测试中立即失败。 我的
TranslatorWorkflow.class
文件位于
{basedir}/bin/testScripts/
中。我的类路径和目标是:

类路径:

<path id="classpath">
    <fileset dir="${basedir}/lib/binaries" includes="*.jar" />
    <pathelement location="${basedir}/bin/testScripts/" />
</path>
<target name="TranslatorWorkflow">
    <mkdir dir="${junit.output.dir}" />
    <junit fork="yes" printsummary="withOutAndErr">
        <formatter type="xml" />
        <test name="testScripts.TranslatorWorkflow" todir="${junit.output.dir}" />
        <classpath refid="classpath" />
    </junit>
</target>

我的build.xml文件中的Translator工作流目标:

<path id="classpath">
    <fileset dir="${basedir}/lib/binaries" includes="*.jar" />
    <pathelement location="${basedir}/bin/testScripts/" />
</path>
<target name="TranslatorWorkflow">
    <mkdir dir="${junit.output.dir}" />
    <junit fork="yes" printsummary="withOutAndErr">
        <formatter type="xml" />
        <test name="testScripts.TranslatorWorkflow" todir="${junit.output.dir}" />
        <classpath refid="classpath" />
    </junit>
</target>

我试图通过添加上面的类路径部分中显示的pathelement行进行模拟,但收到了相同的异常。我已经看过了。我可以想象,我遗漏了一些非常明显的东西,但唉,我似乎不明白。

垃圾猫,试试这个

  <path id="base.path">
    <pathelement path="${sun.boot.class.path}"/>
    <pathelement path="${sun.boot.library.path}"/>
    <fileset dir="${basedir}"> 
       <include name="**.jar"/>
    </fileset>
  </path>

然后在目标元素中

<target name="runTest">
  <mkdir dir="test_reports"/>

  <junit
      fork="true"
      forkmode="once"
      maxmemory="256m">

    <formatter type="plain" usefile="false"/>
    <formatter type="xml"/>

    <classpath refid="base.path"/>

    <batchtest
        haltonerror="true" haltonfailure="true"
        todir="test_reports">

      <fileset dir="${test.build}">
        <include name="**/*Test*.class"/>
        <include name="**/Test*.class"/>
        <include name="**/*Test.classp"/>
        <!-- Exclusions -->
        <exclude name="**/util/*.class"/> 
      </fileset>
    </batchtest>
  </junit>
</target>


至少这就是我管理类路径引用的方式,一切都像一个魔咒一样工作。

类路径应该引用
${basedir}/bin
而不是
${basedir}/bin/testScripts
(即,它应该引用类目录的根目录,而不是类所在的包):



Junit库是否在类路径上?我稍后会尝试一下,以确保它也能正常工作。看起来好像我在引用子目录,而我本应该引用我的类目录的根目录。这正是我暗示给你的@垃圾猫请测试我的答案和评论,如果它有效与否。现在我有了疑问:DIt可能与build.xml文件的具体设置方式有关。我将/lib/binaries删除到我的fileset dir中,然后它抛出了我需要包含junit.jar的内容,如果它不在Ant自己的类路径中(不适用于我,不适用):不过,这可能是Ant构建的方式