Ant-JUnit 错误:Ant 希望 JUnit .jar 位于其类路径中
我对 JUnit 和 Ant 有点陌生。我想知道这个错误是什么意思:
The <classpath> for <junit> must include junit.jar if not in Ant's own classpath
我正在编译一个Java项目,我无法超越这一点。
I am a bit new to JUnit and Ant. I want to know what this error means:
The <classpath> for <junit> must include junit.jar if not in Ant's own classpath
I am compiling a Java project, and I cannot get beyond this point.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
Junit ant 任务的文档提供了如何将 junit.jar 放入类路径的选项列表:
http://ant.apache.org/manual/Tasks/junit.html
为了保存您的查找,下面复制了这些选项。我的偏好是选项 1。
The documentation of the Junit ant task gives a list of options for how to get junit.jar onto the classpath:
http://ant.apache.org/manual/Tasks/junit.html
To save you the lookup, the options are reproduced below. My preference is option 1.
今天我花了几个小时解决这个问题。我通过 Project|Properties|Java Build Path 在 Eclipse 中指定了所有 .jar 文件,但从
Eclipse 运行 Ant 时仍然出现错误。
从命令行运行 Ant 可以正常工作(我的类路径环境变量中有所有内容)。
但在 Eclipse 中,唯一有效的方法是显式地声明元素内的类路径,例如:
如果没有在 junit 元素内显式指定类路径,它每次都会在 Eclipse 中中断,即使只是一个简单的
引用
我不是专家,只是报告今天的工作。
-ctb
I spent a couple hours with this problem today. I had the .jar files all specified in Eclipse via Project|Properties|Java Build Path, but was still getting the
error when running Ant from Eclipse.
Running Ant from the command line would work fine (I had everything in the classpath environment variable).
But in Eclipse the only thing that worked was to explicitly state the classpath inside the elements, e.g.:
Without explicitly specifying the classpath within the junit element, it would break in eclipse every time, even just a bare
reference
I'm no expert, just reporting what worked today.
-ctb
我认为原因如下:junit.jar 不在您的 CLASSPATH 环境变量中。将 junit.jar 添加到您的 CLASSPATH 或将其添加到您在 ant 构建文件中定义的类路径。
这是ant 简介。
I believe that the following is the cause: junit.jar is not in your CLASSPATH environment variable. Either add junit.jar to your CLASSPATH or add it to the classpath that you define in your ant build file.
Here is an introduction to ant.
我不知道这意味着什么,但就我而言,似乎由于 Dropbox 而发生了冲突。重新启动 Netbeans 解决了该问题。可能与我使用Linux和同学使用Windows有关,但我不确定。
“只需重新启动 Netbeans”对于 stackoverflow 的答案来说可能太简单了,但如果有人发布了它,它会节省我一些时间......
I have no clue what it means, but in my case it seems there was a conflict because of Dropbox. Restarting Netbeans resolved the issue. Might have something to do with my using Linux and classmates using Windows, but I'm not sure.
"Just restart Netbeans" might be too simple for a stackoverflow answer, but if someone had posted it, it would have saved me some time...
窗口->首选项->蚂蚁->运行时->类路径 将 junit-xx.jar 添加到全局条目作为外部 jar 文件。
Window -> Preferences -> Ant -> Runtime -> Classpath Add junit-xx.jar to the Global Entries as an external jar file.