java - 找不到taskdef类org.apache.tools.ant.taskdefs.可选.junit.JUnitTask

标签 java ant weblogic8.x

从上一天起我就一直在努力解决这个问题。我们使用Weblogic Workshop 81(WLW)作为IDE。我尝试在 eclipse 中运行 junit,它没有任何问题(没有 taskdef)。

我在 WLW 上尝试了以下方法

第一种方法:我使用了几乎相同的ant文件(如eclipse)在WLW中构建,但在使用时无法找到JunitTask类taskdef 如下所示,它提示如下所示的类

Cannot parse Ant build file: ..... taskdef class org.apache.tools.ant.taskdefs.optional.junit.JUnitTask cannot be found

Build.xml

<project>
 ....
    <path id="MyProject.classpath">
        <pathelement location="${output.directory}/ant-optional.jar" />
        <pathelement location="${output.directory}/junit.jar" />
        <fileset dir="${output.directory}">
            <include name="**/*.jar" />
        </fileset>
        <fileset dir="${platformhome.local.directory}\server\lib\">
            <include name="**/*.jar" />
        </fileset>

        <pathelement path="${class.path}"/>
        <dirset dir="${dest.path}">         
        </dirset>
    </path>

    <path id="classpath.test">
        <fileset dir="C:\tools\Build\ant\apache-ant-1.8.2\lib">
            <include name="**/*.jar" />
        </fileset>
    </path>

    <taskdef name="junit"
      classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask" classpathref="MyProject.classpath">      
    </taskdef>

    <target name="test">      

        <echo>In Test</echo>  
        <mkdir dir="${junit.output.dir}" />
        <junit>
            <classpath refid="MyProject.classpath">
            </classpath>           
            <batchtest todir="${junit.output.dir}">
                <formatter type="plain" usefile="false"/>
                <formatter type="plain" />
                <fileset dir="${src.path}">
                    <include name="**/*Test*.java" />
                </fileset>
            </batchtest>    
        </junit>
    </target>
</project>

我通过在命令提示符中的构建上使用 -diagnostic 标志验证了 ant home(使用 web-logic 使用的 ant 版本,因此我正在针对正确的 ant 版本进行测试)我得到了以下响应

------- Ant diagnostics report -------
Apache Ant version 1.5.3 compiled on August 13 2003

-------------------------------------------
 Implementation Version (JDK1.2+ only)
-------------------------------------------
core tasks     : null
optional tasks : 1.5.3

-------------------------------------------
 ANT_HOME/lib jar listing
-------------------------------------------
ant.home: C:\tools\@#$@##$\bea\weblogic81\server\bin\\..
ant-optional.jar (671546 bytes)
avalon-framework.jar (62694 bytes)
batik.jar (2111580 bytes)
debugging.jar (274343 bytes)
EccpressoAsn1.jar (61543 bytes)
EccpressoCore.jar (133746 bytes)
EccpressoJcae.jar (107821 bytes)
ejbgen.jar (766896 bytes)
fop.jar (1479760 bytes)
jconn2.jar (909569 bytes)
jConnect.jar (764285 bytes)
JDIProxy.jar (86647 bytes)
jms450.jar (24470 bytes)
jms451.jar (25749 bytes)
jms500.jar (26572 bytes)
jms51-interop.jar (4720 bytes)
jms510.jar (26572 bytes)
jsafeFIPS.jar (404439 bytes)
junit.jar (121070 bytes)

这意味着 ANT_HOME 有 ant-optional.jarjunit.jar,其中有 JunitTask.java,负责从 ant 运行单元测试。

我什至在项目的类路径中添加了上面提到的 jar,因此它将与项目一起编译。

第二种方法 这次我从ant文件中删除了taskdef,看看ant是否能够自己找到junit任务来自类路径。它给出了以下异常。

ERROR: Could not create task or type of type: junit.
ERROR: Ant could not find the task or a class this task relies upon.
ERROR: This is common and has a number of causes; the usual 
ERROR: solutions are to read the manual pages then download and
ERROR: install needed JAR files, or fix the build file: 

有人可以给我指点一下吗?谢谢。

最佳答案

我认为你需要阅读classpath, bootstrap class loader and ant's class loader 。请参阅HERE并浏览 <junit>-and-<classpath> 上的三个答案

你似乎也失踪了ant-junit.jar

来自文档。 HERE ,执行以下一项操作:

  • Put both junit.jar and ant-junit.jar in ANT_HOME/lib.
  • Do not put either in ANT_HOME/lib, and instead include their locations in your CLASSPATH environment variable.
  • Add both JARs to your classpath using -lib.
  • Specify the locations of both JARs using a element in a in the build file.
  • Leave ant-junit.jar in its default location in ANT_HOME/lib but include junit.jar in the passed to . (since Ant 1.7)

此外,作为引用,还有一个工作 build.xml HERE 。如果需要,您可以引用该内容。

关于java - 找不到taskdef类org.apache.tools.ant.taskdefs.可选.junit.JUnitTask,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24875521/

相关文章:

java - 在ArToolkit的android java SDK中查找ArMarker和相机之间的距离

java - Ant scriptmapper 不像宣传的那样工作?

java - 数据库选择语句的并发问题

java - 无法使用 document.getElementById 获取元素,返回 null

java - 如果我未在mapreduce程序中设置 'number of reduce tasks',会发生什么情况?

ant - 2 个不匹配的字符串对象的断言/比较被记录为错误而不是失败

java - ClassNotFoundException:通过 ANT 构建 JAR 文件中的主类

java - weblogic 81.(SP6)是否兼容oracle 11 G和Jdk 1.4.2

java - 重复 getter 调用的性能与在局部变量中保存值的性能