Greg,

        I found some interesting comments on the Ant Archives; see [1] and
its further comments on the same thread. Bottom line, it is recommended you
use the -lib flag when invoking ant; so your ant invocation would be:

$ ant -lib /path/to/your/jars -f buildfile.xml

Hope this helps you

Regards
-Luis

[1] 
http://marc.theaimsgroup.com/?l=ant-user&m=109612423713819&w=2 
http://marc.theaimsgroup.com/?l=ant-user&m=109613984207651&w=2

-----Original Message-----
From: Greg Wilson [mailto:[EMAIL PROTECTED]
Sent: Tuesday, October 12, 2004 8:34 AM
To: [EMAIL PROTECTED]
Cc: Cosmo A. DiFazio Jr.
Subject: 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to