ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Peter" <pet...@westerninspection.com>
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"
failureProperty="test.failed">

    <classpath>

      <path refid="test.classpath"/>

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

     </classpath>

     <formatter type="xml" />

       <batchtest todir="${dir.report}">

         <fileset dir="test">

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

         </fileset>

       </batchtest> 

  </junit>

</target>

 

Here are my path definitions:

 

  <path id="project.classpath">

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

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

        <include name="*.jar"/>

      </fileset>

  </path>

   

  <path id="test.classpath">

    <path refid="project.classpath"/>

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

  </path>

 

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: " +
System.getProperty("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:

 

  java.class.path:
e:\j2sdk142\lib\tools.jar;e:\ant\lib\optional.jar;e:\ant\lib\junit.jar;e:\an
t\lib\ant.jar;

 

It appears that

  <classpath>

    <path refid="test.classpath"/>

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

  </classpath>

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

 

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
effect.

 

Thanks for your time.

Peter

 


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

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