Java 找不到taskdef类org.apache.tools.ant.taskdefs.optional.junit.JUnitTask
从最后一天起,我就一直在为这个问题苦苦挣扎。我们使用Weblogic workshop 81(WLW)作为IDE。我试着在eclipse中运行junit,它可以正常工作(没有taskdef) 我在WLW上尝试了以下方法 第一种方法:我在WLW中使用了几乎相同的ant文件(如eclipse),但在使用taskdef(如下面所示)时无法找到JunitTask类,它会抱怨如下所示的类Java 找不到taskdef类org.apache.tools.ant.taskdefs.optional.junit.JUnitTask,java,ant,weblogic8.x,Java,Ant,Weblogic8.x,从最后一天起,我就一直在为这个问题苦苦挣扎。我们使用Weblogic workshop 81(WLW)作为IDE。我试着在eclipse中运行junit,它可以正常工作(没有taskdef) 我在WLW上尝试了以下方法 第一种方法:我在WLW中使用了几乎相同的ant文件(如eclipse),但在使用taskdef(如下面所示)时无法找到JunitTask类,它会抱怨如下所示的类 Cannot parse Ant build file: ..... taskdef class org.apache
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>
这意味着ANT_HOME有ANT optional.jar
&junit.jar
,它有JunitTask.java,负责从ANT运行单元测试
我甚至在项目的类路径中添加了上述JAR,因此它将与项目一起编译
2nd approach这次我从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:
有人能给我指点一下吗。谢谢 我认为您需要阅读
类路径、引导类装入器和ant的类装入器
。查看并浏览-和-
您似乎还缺少antjunit.jar
从医生那里,执行以下操作之一:
- 将junit.jar和ant-junit.jar放在ant_HOME/lib中
- 不要将它们放在ANT_HOME/lib中,而是将它们的位置包含在CLASSPATH环境变量中
- 使用-lib将这两个JAR添加到类路径中
- 使用生成文件中a中的元素指定两个JAR的位置
- 将ant-junit.jar保留在ant_HOME/lib中的默认位置,但将junit.jar包含在传递给的文件中。(自Ant 1.7起)
build.xml
,供参考。如果需要的话,你可以参考一下
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: