ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Donald <dona...@apache.org>
Subject Re: taskdef'ing junit
Date Sun, 18 Nov 2001 06:25:40 GMT
On Sun, 18 Nov 2001 17:15, Jeff Turner wrote:
> Hi,
>
> I'm trying to use <taskdef> to define the <junit> task, so I don't have
> to require all users to copy junit.jar to the $ANT_HOME/lib.
>
> I currently have:
>
> <project name="test_taskdef" default="main" basedir=".">
>     <property name="build.sysclasspath" value="ignore"/>
>
>     <target name="main">
>         <echo>Using jar ${ant.home}/lib/optional.jar</echo>
>         <taskdef name="junit"
> classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask">
> <classpath>
>                 <pathelement location="${ant.home}/lib/optional.jar"/>
>             </classpath>
>         </taskdef>
>     </target>
> </project>

I think you missed a classpath element out of there ;) However even if you 
add junit.jar into classpath it will still not work .. see below.

>
> I get the error:
>
> /home/jeff/tmp/java/ant/taskdef/build.xml:8: taskdef class
> org.apache.tools.ant.taskdefs.optional.junit.JUnitTask cannot be found
>
> I've verified that ${ant.home}/lib/optional.jar exists and contains that
> class. Should this be possible? I've tested with Ant 1.4 and the latest
> from CVS.

Unfortunately it isn't possible. The reason is that Ant will go looking for 
the junit task. It will first call the loadClass() in the ClassLoader created 
by taskdef. However this ClassLoader will first check the parent classloader 
for the junit class. It will find the junit class (because it is in 
${ant.home}/lib/optional.jar). However unless junit.jar is also in the parent 
classloader, the JVM will be unable to locate the required junit classes and 
thus will report that it fails to load the junit task.

So you will have to remove optional.jar from ${ant.home}/lib if you want to 
taskdef junit.

-- 
Cheers,

Pete

*-----------------------------------------------------------------------*
PROGRAM: n.  a magic spell cast over a computer allowing it to turn
one's input into error messages.  v.t.  to engage in a pastime similar
to banging one's head against a wall, but with fewer opportunities for 
reward.
*-----------------------------------------------------------------------*

--
To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>


Mime
View raw message