Java JAR Archives and classpath on MS Windows

The JVM class loader will only find and use JAR archives that are listed in the classpath. There are several ways to add a JAR to the classpath:

  1. Copy the JAR to one of the directories listed in the CLASSPATH environment variable. To see the current value of the CLASSPATH environment variable, open a MS-DOS prompt and type:
    echo %CLASSPATH%
    Another way of viewing the classpath is to run this Java code:
    String classpath = System.getProperty("java.class.path");
  2. Modify the CLASSPATH environment variable to also include the directory containing the JAR archive. This is typically done via the Windows Computer-->Properties-->Advanced dialog. For more information, these Google searches produce good results: "windows 7 environment variables", "windows xp environment variables", etc.
  3. Set the classpath at runtime. There are several possible ways of doing this:
    1. Use the -classpath option:
      javac -classpath ".;C:/chilkatJava/chilkat.jar"
      java -classpath ".;C:/chilkatJava/chilkat.jar" Test
    2. Use the -Djava.class.path system property:
      javac -Djava.class.path=.;C:/chilkatJava/chilkat.jar
      java -Djava.class.path=.;C:/chilkatJava/chilkat.jar Test
    3. Use the CLASSPATH environment variable
      set CLASSPATH=%CLASSPATH%;C:\chilkatJava\chilkat.jar
      javac Test
      java Test

    IMPORTANT:On Windows systems, the semicolon character should be used for the path separator. However, on Linux systems, the colon character should be used.