You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by William Lee <wl...@sendmail.com> on 2001/03/01 18:47:01 UTC
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?
Will
Re: Setting classpath for optional task
Posted by William Lee <wl...@sendmail.com>.
Yes, I've actually make a copy of the code posted and I still got the
error. I've changed the directory to my directory where I have my
junit.jar.
Will
Nico Seessle wrote:
>
> ----- Original Message -----
> From: "William Lee" <wl...@sendmail.com>
> To: <an...@jakarta.apache.org>
> Sent: Friday, March 02, 2001 11: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:
> >
>
> OK, let's clarify what you mean with "I've tried this". Have you copied my
> sample exactly as it was written?
>
> If yes, you should really change the "<fileset dir="...">-part of my example
> to point to the directory your junit.jar is in. If no I will try it myself.
>
> Nico
Re: Setting classpath for optional task
Posted by Nico Seessle <ni...@apache.org>.
----- Original Message -----
From: "William Lee" <wl...@sendmail.com>
To: <an...@jakarta.apache.org>
Sent: Friday, March 02, 2001 11: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:
>
OK, let's clarify what you mean with "I've tried this". Have you copied my
sample exactly as it was written?
If yes, you should really change the "<fileset dir="...">-part of my example
to point to the directory your junit.jar is in. If no I will try it myself.
Nico
Re: Setting classpath for optional task
Posted by William Lee <wl...@sendmail.com>.
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/build.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" <wl...@sendmail.com>
> To: "Ant User" <an...@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
Re: Setting classpath for optional task
Posted by Stefan Bodewig <bo...@apache.org>.
Gary Lawson <ga...@sferics.com> wrote:
> We used
<snip/>
> <junit haltonfailure="off" haltonerror="off" printsummary="on" >
> <classpath refid="project.classpath" />
> </junit>
This is the way to set the CLASSPATH for the testcases.
What Wiliam asked for - at least this is what I and obviously Nico
understood - is something different. He wants to set the CLASSPATH the
task itself is loaded from.
Nico's answer should solve the problem here.
Stefan
RE: Setting classpath for optional task
Posted by Gary Lawson <ga...@sferics.com>.
We used
<path id="project.classpath" >
<pathelement path="${tomcat_home}/webapps/${project}/WEB-INF/classes" />
<pathelement location="${ant_home}/lib/ant.jar" />
<pathelement location="${ant_home}/lib/optional.jar" />
<pathelement
location="${build_dir}/common/servlet2.2/servletapi/lib/servlet.jar" />
<pathelement location="${build_dir}/common/junit3.2/junit.jar" />
<pathelement location="${build_dir}/common/HttpUnit/lib/httpunit.jar" />
<pathelement
location="${build_dir}/common/JTidy/jtidy-04aug2000r6/build/Tidy.jar" />
</path>
.
.
.
[snip]
.
.
<target name="runtests" depends="init" >
<junit haltonfailure="off" haltonerror="off" printsummary="on" >
<classpath refid="project.classpath" />
<formatter type="plain" />
<test name="com.blah.blah.AllTests" haltonfailure="off"
haltonerror="off" outfile="alltests" />
</junit>
</target>
HTH
Gary
-----Original Message-----
From: Nico Seessle [mailto:nico@apache.org]
Sent: 01 March 2001 19:19
To: ant-user@jakarta.apache.org
Subject: Re: Setting classpath for optional task
----- Original Message -----
From: "William Lee" <wl...@sendmail.com>
To: "Ant User" <an...@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
Re: Setting classpath for optional task
Posted by Nico Seessle <ni...@apache.org>.
----- Original Message -----
From: "William Lee" <wl...@sendmail.com>
To: "Ant User" <an...@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