I'v been struggling with this issue since the last one day. We use Weblogic workshop 81(WLW) as the IDE. I tried running junit in eclipse and it works with no issues(without taskdef).
I tried the following approaches on 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
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>
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
------- 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.
I even added the above mentioned jars in the classpath of the project so, it will compile with the project.
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. 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.