ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Peter" <>
Subject Classpath problem inside a JUnit task
Date Fri, 05 Dec 2003 23:57:12 GMT
I’m hoping someone can help me with a problem.  This may be a bug but more
likely my ignorance.  I have the following task in an ant build file:


<target name="junit" depends="build">

  <junit printsummary="on" fork="false" errorProperty="test.failed"


      <path refid="test.classpath"/>

        <pathelement path="${java.class.path}"/>


     <formatter type="xml" />

       <batchtest todir="${}">

         <fileset dir="test">

           <include name="**/Test*.java"/>






Here are my path definitions:


  <path id="project.classpath">

    <pathelement location="${dir.class}"/>

      <fileset dir="${env.JAVA_LIBS}">

        <include name="*.jar"/>




  <path id="test.classpath">

    <path refid="project.classpath"/>

      <path location="${dir.test}"/>



All of my variables are set with proper values.  


The problem I’m having is this:  Ant spawns JUnit to run the tests which DO
get loaded and begin executing.  The classes I’m testing need to open a file
somewhere on the classpath so they start looking for it:


  String classPath  = System.getProperty("java.class.path");

  // walk the classpath and look for data files here


My classes can NOT find my data files anywhere in the classpath so I added 


  System.out.println("java.class.path: " +


in order to see what I’d done wrong.  Much to my surprise my class doesn’t
get much of a classpath at all.  This is the output:




It appears that


    <path refid="test.classpath"/>

    <pathelement path="${java.class.path}"/>


does not get sent to the test class in the “java.class.path” system


I’m curious how java could have even loaded the test that is running as the
test itself is in one directory and the class its testing is in another,
neither of which are seen on the classpath.  Obviously there must be another
mechanism for specifying a classpath that the classloader uses.  I’ve worked
around this problem by setting fork=”true” but I’d like a better solution
due to performance issues.  Note that removing the line <pathelement
path="${java.class.path}"/> when fork=”false” doesn’t seem to have an


Thanks for your time.



Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (
Version: 6.0.545 / Virus Database: 339 - Release Date: 11/27/2003

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message