ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Pringle <>
Subject RE: Setting classpath for optional task
Date Fri, 02 Mar 2001 23:24:22 GMT
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". (I assume you can't dynamically change
the classpath for the system classloader? - maybe so, and it's a feature to
add to ant).

The easiest way to fix your problem would be to put junit.jar in the
$ant_home/lib directory (all jars in this directory are automatically added
to the classpath by the start script), or a symlink to it if you're on a
*nix platform.  Second easiest would be to require a "JUNIT_HOME" env
variable that points to the appropriate location, and modify the start
script to a) check that the env var is defined and b) add the junit.jar
library to the classpath like the other jars (for ant) are.  You could even
have it make some guesses as to the location if JUNIT_HOME is not defined (I
think the scripts do this if JAVA_HOME and ANT_HOME are not defined).

-----Original Message-----
From: William Lee []
Sent: Friday, March 02, 2001 2:25 PM
Subject: Re: Setting classpath for optional task

I've try this but I still get a junit/framework/TestListener class not
found error.  Note that my junit.jar is not in the same ant's lib
directory.  I'm using JUnit 3.5 and Ant 1.3b3.  Here is the stack trace:

Could not create task of type: junit due to
java.lang.NoClassDefFoundError: junit/framework/TestListener
--- Nested Exception ---
java.lang.NoClassDefFoundError: junit/framework/TestListener
	at java.lang.ClassLoader.defineClass0(Native Method)
	at java.lang.ClassLoader.defineClass(
	at Method)
	at java.lang.ClassLoader.loadClass(
	at sun.misc.Launcher$AppClassLoader.loadClass(
	at java.lang.ClassLoader.loadClass(
	at java.lang.ClassLoader.loadClassInternal(
	at java.lang.Class.newInstance0(Native Method)
	at java.lang.Class.newInstance(

The build file would work if I specify the junit.jar in the
LOCALCLASSPATH variable in the script that invokes Ant.  

Can anyone tell me why?


Nico Seessle wrote:
> ----- Original Message -----
> From: "William Lee" <>
> To: "Ant User" <>
> Sent: Thursday, March 01, 2001 6:47 PM
> Subject: Setting classpath for optional task
> > Is there a way I can set the classpath for the optional tasks WITHIN the
> > ant build.xml?  For now, if I want to use a task such as JUnit, I need
> > to set the classpath explicitly before I call the ant main class.  Since
> > I don't really want to depend on the environment variable CLASSPATH for
> > various reasons, I can't really use the "ant" script to invoke the
> > build.xml that has a JUunit task.  I ended up writing something similar
> > to the "ant" with my custom CLASSPATH.  Is there anyway to get around
> > it?
> You could try to "redefine" the junit-task using something like
> <taskdef name="junit"
> classname="">
>   <classpath>
>     <fileset dir="./lib">
>        <include name="junit.jar"/>
>     </fileset>
>   </classpath>
> </taskdef>
> Don't know if this works (and if I have made some errors above) - just try
> it.
> Nico

View raw message