如何检查我的电脑中是否安装了hamcrest.jar

时间:2014-07-24 06:12:47

标签: java eclipse ant junit

我正在尝试使用在Eclipse IDE中插入Ant的JUnit来测试几个单元。我收到了以下错误。

test:
[junit] Testsuite: TestMessageUtil
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0.004 sec
[junit] Testcase: initializationError(TestMessageUtil): Caused an ERROR
[junit] org/hamcrest/SelfDescribing
[junit] java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
[junit]     at java.lang.ClassLoader.defineClass1(Native Method)
[junit]     at java.lang.ClassLoader.defineClassCond(Unknown Source)
[junit]     at java.lang.ClassLoader.defineClass(Unknown Source)
[junit]     at java.security.SecureClassLoader.defineClass(Unknown Source)
[junit]     at java.net.URLClassLoader.defineClass(Unknown Source)
[junit]     at java.net.URLClassLoader.access$000(Unknown Source)
[junit]     at java.net.URLClassLoader$1.run(Unknown Source)
[junit]     at java.security.AccessController.doPrivileged(Native Method)
[junit]     at java.net.URLClassLoader.findClass(Unknown Source)
[junit]     at sun.misc.Launcher$ExtClassLoader.findClass(Unknown Source)
[junit]     at java.lang.ClassLoader.loadClass(Unknown Source)
[junit]     at java.lang.ClassLoader.loadClass(Unknown Source)
[junit]     at java.lang.reflect.Constructor.newInstance(Unknown Source)
[junit]     at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
[junit]     at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:424)
[junit]     at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:138)
[junit] Caused by: java.lang.ClassNotFoundException: org.hamcrest.SelfDescribing
[junit]     at java.net.URLClassLoader$1.run(Unknown Source)
[junit]     at java.security.AccessController.doPrivileged(Native Method)
[junit]     at java.net.URLClassLoader.findClass(Unknown Source)
[junit]     at sun.misc.Launcher$ExtClassLoader.findClass(Unknown Source)
[junit]     at java.lang.ClassLoader.loadClass(Unknown Source)
[junit]     at java.lang.ClassLoader.loadClass(Unknown Source)
[junit] Test TestMessageUtil FAILED
BUILD SUCCESSFUL

请帮忙。我知道我必须在我的类路径中包含hamcrest.jar。但是从哪里可以找到那个jar文件?

2 个答案:

答案 0 :(得分:1)

  • 下载jar
  • 转到Eclipse项目 - > rt click - >属性 - > Java构建路径
  • 点击Libraries选项卡 - >添加外部jar
  • 浏览到您下载的位置并添加jar
  • 蚂蚁使用

其中dependency.lib指向包含所需jar的文件夹

<path id="compile.classpath">
                <fileset dir="${dependecies.lib}">
                    <include name="*.jar" />
                </fileset>
        </path>

答案 1 :(得分:1)

您似乎在运行时遇到问题,因此请更改其类路径的配置:

  1. 右键单击您的文件(junit或ant)
  2. 以 - &gt;运行Junit(或Ant)
  3. 在用户条目
  4. 中添加hamcrest-core-1.3.jar作为外部jar
  5. 最后重试运行
  6. enter image description here