ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From William Lee <>
Subject Re: Setting classpath for optional task
Date Mon, 05 Mar 2001 17:38:09 GMT
I've tried what Nico has suggested (in fact, almost an identical copy
with modification to where I put my junit.jar file) and I still get the
class not found error.  I'm using JUnit 3.5 and Ant 1.3b3.  If I invoke
the same build file with the CLASSPATH for JUnit already set before I
invoke Ant, then it would actually work.

Here is a segment of my build file:

<?xml version="1.0"?>

<!-- Build file for application -->
<project name="test" default="compile" basedir=".">

  <!-- Build classpath -->
  <path id="classpath">
    <fileset dir="lib">
      <include name="**/*.jar"/>
    <fileset dir="../lib">
      <include name="**/*.jar"/>
    <pathelement path="${java.class.path}"/>
    <pathelement path="../classes"/>

   <!--  I was using this before, but didn't work also.  My JUnit is in
the ../lib directory. 
         ANT_HOME is the current directory (where this build.xml is)
    <classpath refid="classpath"/>
  <taskdef name="junit"
      <fileset dir="../lib">
        <include name="junit.jar"/>

  .... Some other definitions ....

=================================================================== -->
  <!-- Run the Unit tests defined in this directory
tree                   -->
=================================================================== -->  
  <target name="run-tests" depends="compile-tests">
    <mkdir dir="${test.results}"/>
    <junit printsummary="yes" haltonfailure="no">
      <classpath refid="classpath"/>
      <formatter type="xml" />
      <batchtest fork="yes" todir="${test.results}">
        <fileset dir="${src.dir}/java">
          <include name="**/test/*Test*.java" />
          <exclude name="**/" />


Hope this helps.


> Jason Pringle <> wrote:
> > I'll make a guess (ant dev guys keep me honest here)...
> >
> > The optional tasks are loaded by the "main" ant startup, which means
> > any referenced classes (such as JUnit's stuff) must be on the
> > classpath that Ant was started with in the "ant script".
> Right, *unless* the task has been defined by a <taskdef> that comes
> with a classpath definition of its own. And this is exactly what Nico
> suggested the first time.
> I vaguely remember that taskdefs with nested classpaths didn't work
> correctly in Ant 1.2. William, could you please try to (re)define the
> junit task with the correct classpath (containing JUnit itself) with
> Ant 1.3 and see whether this makes any difference?
> Thanks
>         Stefan

View raw message