ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Pringle <Jas...@captura.com>
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 [mailto:wlee@sendmail.com]
Sent: Friday, March 02, 2001 2:25 PM
To: ant-user@jakarta.apache.org
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:

/home/wlee/smi/SendmailGUI/dist/turbine/webapps/ListEditor/WEB-INF/build/bui
ld.xml:210:
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(ClassLoader.java:486)
	at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:111)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)
	at java.lang.Class.newInstance0(Native Method)
	at java.lang.Class.newInstance(Class.java:237)
	at org.apache.tools.ant.Project.createTask(Project.java:439)
	at
org.apache.tools.ant.UnknownElement.maybeConfigure(UnknownElement.java:83)
	at org.apache.tools.ant.Target.execute(Target.java:152)
	at org.apache.tools.ant.Project.runTarget(Project.java:898)
	at org.apache.tools.ant.Project.executeTarget(Project.java:536)
	at org.apache.tools.ant.Project.executeTargets(Project.java:510)
	at org.apache.tools.ant.Main.runBuild(Main.java:421)
	at org.apache.tools.ant.Main.main(Main.java:149)


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?

Will

Nico Seessle wrote:
> 
> ----- Original Message -----
> From: "William Lee" <wlee@sendmail.com>
> To: "Ant User" <ant-user@jakarta.apache.org>
> 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="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask">
>   <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

Mime
View raw message