2
votes

I'm using Cygwin under Windows XP, and I'm trying to get Ant to use JUnit without coding any classpath entries for it. The doc for JUnit says I can:

Put both junit.jar and ant-junit.jar in ANT_HOME/lib.

My handy-dandy copy of JUnit in Action says:

You may have noticed that you don't explicitly add the JUnit JAR to the classpath. Remember that when you installed Ant, you copied the JUnit JAR file to the ${ANT_HOME}/lib directory in order to use the junit Ant task. Because junit.jar is already on your classpath, you don't need to specify it in the javac task to compile your tests.

$ANT_HOME is set to the Ant installation directory. In the lib subdirectory, I see ant-junit.jar (installed with Ant) and junit-4.9.jar (copied by me). Seems okay, right? But the test compile step fails:

[javac] Compiling 1 source file to E:\tools\ctg\bin\test
[javac] E:\tools\ctg\src\test\TestAll.java:3: package org.junit does not exist
[javac] import org.junit.*;

Et cetera. I tried renaming junit-4.9.jar to junit.jar. No joy. I peeked in the jar file and saw that the package does exist inside of it. In fact, the compiles work fine if I explicitly include that very jar file in the Ant classpath.

Bleh. Any thoughts about what might be wrong? Thanks.

EDIT: By request, here's the javac target:

<path id="classpath">
   <pathelement location="${app-bin}"/>
   <pathelement location="${test-bin}"/>
   <!--pathelement location="${junit-bin}"/-->
</path>

<target name="compile-test" depends="compile-app">
   <javac srcdir="${test-src}"
          destdir="${test-bin}"
          source="${java}"
          target="${java}"
          debug="on"
          includeantruntime="false">
      <compilerarg value="-Xlint"/>
      <classpath refid="classpath"/>
   </javac>
</target>

Note that the JUnit binary is commented out. My goal is to delete it and have the compile work.

2
could you post your javac target?oers
The javac target is now in the question text.Singlestone

2 Answers

6
votes

includeantruntime="false" tells ant to not include the libs in the lib directory for the compile.

You have to add the jar to a classpath, which you will give to the javac target. Or set the property to true.

0
votes

Try removing the version number from the junit jar file name.
i.e. rename junit-4.9.jar to junit.jar