如何将 `hamcrest-core-1.3.jar` 添加到 windows 中的类路径变量?

How to add `hamcrest-core-1.3.jar` to the classpath variable in windows?

我的类路径 linked 到包含 hamcrest-core-1.3.jarjunit-4.12.jar 的 junit 主页。 junit 似乎已被识别,但我得到了 NoClassDefFoundError: org/hamcrest/SelfDescribing

我想我必须 link 以某种方式将 hamcrest 添加到类路径变量,但我不确定如何。

这是我的类路径变量的内容:

%CLASSPATH%;%JUNIT_HOME%\junit-4.12.jar;.;

根据 Java 8 Classpath specs,您可以将类路径条目更改为:

%CLASSPATH%;%JUNIT_HOME%/*;.;

具体来说:

Class path entries can contain the base name wildcard character (*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example, the class path entry mydir/* specifies all JAR files in the directory named mydir. A class path entry consisting of * expands to a list of all the jar files in the current directory. Files are considered regardless of whether they are hidden (have names beginning with '.').