You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Greg Wilson <gv...@cs.toronto.edu> on 2004/10/12 15:34:21 UTC
Ant + JUnit problems
Hi everyone. I can now make Ant + JUnit work on my machine, but only by
adding files to the Ant installation. I do *not* want to tell my students
they have to do this --- my experience is that mucking with third-party
installs leads almost instantly to maintenance migraines. So, here's what
I've got; if anyone can propose a cleaner solution than copying junit.jar
into $ANT_HOME/lib, I'd like to hear it.
- Project layout is pretty standard:
./
build.xml
src/
User.java
tst/
TestUser.java
class/
...User.class and TestUser.class put here...
lib/
...the usual suspects --- more detail below...
I've installed JUnit in C:/junit3.8.1 (JUNIT_HOME), and Ant is in
C:/apache-ant-1.6.2 (ANT_HOME).
- Relevant parts of my build.xml are:
<path id="cpath.run">
<fileset dir="${lib}">
<include name="**/*.jar"/>
</fileset>
<pathelement location="${class}" />
</path>
and
<target name="test">
<junit fork="yes" printsummary="on">
<classpath refid="cpath.run" />
<formatter type="plain" usefile="false" />
<test name="TestUser" todir="${report}" />
</junit>
</target>
- My CLASSPATH is set to 'C:/junit3.8.1/junit.jar;.', but Ant doesn't pay
attention to that---it only cares about the classpath set in
'build.xml'. So, copy 'junit.jar' to my project's 'lib' directory: that
makes everything compile, but when I try to run, I get:
"Ant could not find the task or a class this task relies upon."
followed by another screenful of messages.
- The documentation says, "You must have junit.jar and the class files for
the <junit> task in the same classpath." 'cpath.run' includes both
'junit.jar' and my generated class files, but not ant-junit.jar. So,
re-set CLASSPATH to
'C:/junit3.8.1/junit.jar;C:/apache-ant-1.6.2/lib/ant-junit.jar;.'.
Doesn't make a difference.
- Try copying ant-junit.jar to my 'lib' folder, so that it will be
included in my 'cpath.run'. No good; remove it.
- As I said above, I do *not* want to recommend to students that they
start moving files around in third-party installations, since it
quickly leads to maintenance nightmares. However, let's see if copying
'junit.jar' into '$ANT_HOME/lib' makes a difference: yup, that makes my
tests run. Delete it again and keep going.
- What about removing 'ant-junit.jar' from '$ANT_HOME/lib' as the FAQ
entry at:
http://ant.apache.org/faq.html#delegating-classloader
seems to suggest? (Right at the bottom, under the heading "Using The
Second Option with Ant 1.6 and later"). This leaves me with 'junit.jar'
and 'ant-junit.jar' in my 'lib' directory, and neither in '$ANT_HOME/lib'.
Nope, doesn't work.
As I said in the intro, my goal isn't just to get this to work, but to get
it to work in a way I feel comfortable showing to undergraduate students.
Advice would be welcome.
Thanks,
Greg
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Ant + JUnit problems
Posted by Ivan Ivanov <ra...@yahoo.com>.
Hi Greg,
to be honest, I hardly see any reason of *not* placing
junit.jar in $ANT_HOME/lib as it saves a lot of fuss.
Anyway, here are some more ways, that prevents from
moving files in and out distribution:
1) You can place junit.jar (and all third party jars
required by ant optional task) in user's home
directory and Ant will pick them correctly. No need to
move anything in $ANT_HOME/lib.
2) You can place junit.jar in any directory, say
C:/thirdpartyJars and then pass that directory as a
parameter of -lib option to ant starting script:
ant -lib C:/thirdpartyJars test
Again no need to move anything in $ANT_HOME/lib.
3) (Requires moving a file out of ant distribution)
> - The documentation says, "You must have junit.jar
> and the class files for
> the <junit> task in the same classpath."
IMHO "in the same classpath" means "loaded by same
classloader". So you can do this: place junit.jar in
any directory say C:\thirdpartyJars and then move
ant-junit jar from $ANT_HOME/lib to C:\thirdpartyJars
and then redefine junit task in this way:
<path id="junit.cp">
<fileset dir="C:\thirdpartyJars">
<include name="junit.jar"/>
<include name="ant-junit.jar"/>
</fileset>
</path>
<taskdef name="junit"
classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"
classpathref="junit.cp"/>
Here the jars are loaded by one and the same
classloader and so it works. but in most cases <junit>
is used with <junitreport> task that is defined in
ant-junit.jar, so I should taskdef it too and I am too
lazy to do it. Anyway, it is a good exercise in
classpaths and classloading; you can even ask your
students to extend the corresponding entry in Ant's
FAQ and explain it thoroughly :)).
HTH Ivan
P.S. I started my career as a teaching assistant in
Computer Science courses, and I have also wonder a lot
how to explain and resolve classpath issues in my
lessons, so I wish you great luck with your
activities.
> 'cpath.run' includes both
> 'junit.jar' and my generated class files, but not
> ant-junit.jar. So,
> re-set CLASSPATH to
>
>
'C:/junit3.8.1/junit.jar;C:/apache-ant-1.6.2/lib/ant-junit.jar;.'.
> Doesn't make a difference.
>
> - Try copying ant-junit.jar to my 'lib' folder, so
> that it will be
> included in my 'cpath.run'. No good; remove it.
>
> - As I said above, I do *not* want to recommend to
> students that they
> start moving files around in third-party
> installations, since it
> quickly leads to maintenance nightmares. However,
> let's see if copying
> 'junit.jar' into '$ANT_HOME/lib' makes a
> difference: yup, that makes my
> tests run. Delete it again and keep going.
>
> - What about removing 'ant-junit.jar' from
> '$ANT_HOME/lib' as the FAQ
> entry at:
>
>
>
http://ant.apache.org/faq.html#delegating-classloader
>
> seems to suggest? (Right at the bottom, under the
> heading "Using The
> Second Option with Ant 1.6 and later"). This
> leaves me with 'junit.jar'
> and 'ant-junit.jar' in my 'lib' directory, and
> neither in '$ANT_HOME/lib'.
> Nope, doesn't work.
>
> As I said in the intro, my goal isn't just to get
> this to work, but to get
> it to work in a way I feel comfortable showing to
> undergraduate students.
> Advice would be welcome.
>
> Thanks,
> Greg
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@ant.apache.org
> For additional commands, e-mail:
> user-help@ant.apache.org
>
>
_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org