Ant 无法识别其 lib 目录中的 JUnit jar?
我在 Windows XP 下使用 Cygwin,并且尝试让 Ant 使用 JUnit,而无需为其编写任何类路径条目。 JUnit 的文档说我可以:
将 junit.jar 和 ant-junit.jar 放入 ANT_HOME/lib 中。
我的《JUnit in Action》的实用副本中写道:
您可能已经注意到,您没有显式地将 JUnit JAR 添加到类路径中。请记住,安装 Ant 时,您将 JUnit JAR 文件复制到 ${ANT_HOME}/lib 目录,以便使用 junit Ant 任务。由于 junit.jar 已位于您的类路径中,因此您无需在 javac 任务中指定它来编译测试。
$ANT_HOME 设置为 Ant 安装目录。在lib子目录中,我看到ant-junit.jar(与Ant一起安装)和junit-4.9.jar(由我复制)。看起来不错,对吧?但测试编译步骤失败:
[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.*;
等等。我尝试将 junit-4.9.jar 重命名为 junit.jar。没有喜悦。我查看了 jar 文件,发现该包确实存在于其中。事实上,如果我在 Ant 类路径中显式包含该 jar 文件,则编译工作正常。
布莱赫。对于可能出什么问题有什么想法吗?谢谢。
编辑:根据请求,这是 javac 目标:
<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>
请注意,JUnit 二进制文件已被注释掉。我的目标是删除它并进行编译工作。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
includeantruntime="false"
告诉 ant 不要包含库 在 lib 目录中进行编译。您必须将 jar 添加到类路径中,并将其提供给 javac 目标。或者将该属性设置为 true。
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.
尝试从 junit jar 文件名中删除版本号。
即重命名 junit-4.9.jar 为 junit.jar
Try removing the version number from the junit jar file name.
i.e. rename junit-4.9.jar to junit.jar