Search code examples
javajunitjunit4hamcrest

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


My classpath is linked to junit home which contains both hamcrest-core-1.3.jar and junit-4.12.jar. The junit seems to be recognized but I'm getting a NoClassDefFoundError: org/hamcrest/SelfDescribing.

I think I have to link the hamcrest to the classpath variable somehow but I'm not sure how.

This is my classpath variable's contents:

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


Solution

  • Per Java 8 Classpath specs you could change your classpath entry to:

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

    Specifically:

    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 '.').