简体   繁体   English

找不到taskdef类org.apache.tools.ant.taskdefs.optional.junit.JUnitTask

[英]taskdef class org.apache.tools.ant.taskdefs.optional.junit.JUnitTask cannot be found

I'v been struggling with this issue since the last one day. 自上一天以来,我一直在努力解决这个问题。 We use Weblogic workshop 81(WLW) as the IDE. 我们使用Weblogic Workshop 81(WLW)作为IDE。 I tried running junit in eclipse and it works with no issues(without taskdef ). 我尝试在eclipse中运行junit,并且没有问题(没有taskdef )。

I tried the following approaches on WLW 我在WLW上尝试了以下方法

1st Approach: I've used an almost same ant file(like eclipse) to build in the WLW, but it is no able to find JunitTask class when using taskdef like below, it complaints about the class like below 第一种方法:我在WLW中使用了几乎相同的ant文件(如eclipse)来构建,但是在使用如下所示的taskdef时无法找到JunitTask类,它抱怨如下所示的类

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

Build.xml 在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>

I verified the ant home by using -diagnostic flag on the build in the command prompt(using the ant version used by web-logic so I'm testing against the right ant version) i got the following response 我通过在命令提示符下的构建中使用-diagnostic标志验证了蚂蚁之家(使用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)

Meaning that the ANT_HOME has the ant-optional.jar & junit.jar which has the JunitTask.java which is responsible for running unit tests from ant. 这意味着ANT_HOME具有ant-optional.jarjunit.jar ,后者具有JunitTask.java,负责从ant运行单元测试。

I even added the above mentioned jars in the classpath of the project so, it will compile with the project. 我什至在项目的类路径中添加了上面提到的jar,因此它将与项目一起编译。

2nd approach this time I removed the taskdef from the ant file to see if the ant is able to find the junit task by itself from the classpath. 这次的第二种 方法是,我从ant文件中删除了taskdef ,以查看ant能否自己从类路径中找到junit任务。 It gave out the following exception. 它给出了以下例外。

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: 

Could some one provide me pointers on this. 有人可以为我提供有关此方面的建议吗? Thanks. 谢谢。

i think you need to read about classpath, bootstrap class loader and ant's class loader . 我认为您需要阅读有关classpath, bootstrap class loader and ant's class loader See HERE and go through the three answere on <junit>-and-<classpath> 请参阅此处,并在<junit>-and-<classpath>上进行三个回答

you also seem to be missing ant-junit.jar . 您似乎还缺少ant-junit.jar

from the doc. 从文档。 HERE , perform ONE of the following: 这里 ,请执行下列操作之一

  • Put both junit.jar and ant-junit.jar in ANT_HOME/lib. 将junit.jar和ant-junit.jar都放在ANT_HOME / lib中。
  • Do not put either in ANT_HOME/lib, and instead include their locations in your CLASSPATH environment variable. 不要将它们放在ANT_HOME / lib中,而是将它们的位置包括在CLASSPATH环境变量中。
  • Add both JARs to your classpath using -lib. 使用-lib将两个JAR都添加到您的类路径中。
  • Specify the locations of both JARs using a element in a in the build file. 使用构建文件中的元素指定两个JAR的位置。
  • Leave ant-junit.jar in its default location in ANT_HOME/lib but include junit.jar in the passed to . 将ant-junit.jar保留在ANT_HOME / lib中的默认位置,但将junit.jar包含在传递给中。 (since Ant 1.7) (自Ant 1.7起)

also, for reference, there's a working build.xml HERE . 同时,以供参考,有一个工作build.xml 这里 you may refer that, if needed . 如果需要 ,您可以参考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 原因:找不到类org.apache.tools.ant.taskdefs.optional.XMLValidateTask - Cause: the class org.apache.tools.ant.taskdefs.optional.XMLValidateTask was not found 找不到taskdef类org.apache.catalina.ant.InstallTask - taskdef class org.apache.catalina.ant.InstallTask cannot be found Ant:[xslt] java.lang.ClassNotFoundException:org.apache.tools.ant.taskdefs.optional.TraXLiaison - Ant: [xslt] java.lang.ClassNotFoundException: org.apache.tools.ant.taskdefs.optional.TraXLiaison 如何为ant安装org.apache.tools.ant.taskdefs.optional.Rpm - How to install org.apache.tools.ant.taskdefs.optional.Rpm for ant taskdef 类 com.sun.tools.ws.ant.WsImport 无法在“Java Web 服务教程”之后找到 - taskdef class com.sun.tools.ws.ant.WsImport cannot be found Following “The java web services tutorial” 使用包含的 jar 文件从 Apache Ant 运行 JUnit 导致“未找到 JUnitTask” - Running JUnit from Apache Ant with included jar file results in "JUnitTask was not found" 找不到taskdef ant任务 - The taskdef ant task cannot be found 如何修复Java lang.ClassNotFoundException:org.apache.tools.ant.taskdefs.Execute - How to fix java lang.ClassNotFoundException: org.apache.tools.ant.taskdefs.Execute Ant Build - 找不到任务定义 - Ant Build - taskdef cannot be found 使用classloader AntClassLoader []无法找到ant taskdef类 - ant taskdef class cannot be found using the classloader AntClassLoader[]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM