【发布时间】:2014-07-21 21:57:14
【问题描述】:
从前一天开始,我一直在努力解决这个问题。我们使用 Weblogic Workshop 81(WLW) 作为 IDE。我尝试在 Eclipse 中运行 junit,它没有问题(没有 taskdef)。
我在 WLW 上尝试了以下方法
第一种方法:我在 WLW 中使用了几乎相同的 ant 文件(如 eclipse),但使用时找不到 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.jar 和 junit.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:
有人能给我指点一下吗?谢谢。
【问题讨论】:
标签: java ant weblogic8.x