Return-Path: Mailing-List: contact ant-user-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list ant-user@jakarta.apache.org Received: (qmail 68907 invoked from network); 2 Mar 2001 23:24:21 -0000 Received: from unknown (HELO gibraltar.captura.com) (4.23.73.19) by h31.sny.collab.net with SMTP; 2 Mar 2001 23:24:21 -0000 Received: by GIBRALTAR with Internet Mail Service (5.5.2650.21) id ; Fri, 2 Mar 2001 15:24:23 -0800 Message-ID: <168B2A5F6A99D4119E200008C7C9CA80DE3568@GIBRALTAR> From: Jason Pringle To: "'ant-user@jakarta.apache.org'" Subject: RE: Setting classpath for optional task Date: Fri, 2 Mar 2001 15:24:22 -0800 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2650.21) Content-Type: text/plain; charset="iso-8859-1" X-Spam-Rating: h31.sny.collab.net 1.6.2 0/1000/N 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" > 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 > > classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"> > > > > > > > > Don't know if this works (and if I have made some errors above) - just try > it. > > Nico