MacOSX Java JAR Archives and classpath
The JVM class loader can only find and use JAR archives that are listed in the classpath. There are several ways to add a JAR to the classpath:
- 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 terminal and type:
echo $CLASSPATH
Another way of viewing the classpath is to run this Java code:String classpath = System.getProperty("java.class.path"); System.out.println(classpath);
- Modify the CLASSPATH environment variable to also include the directory containing the JAR archive.
In csh, the CLASSPATH environment variable is modified with the setenv command. The format is:
setenv CLASSPATH path1:path2:...
In sh, the CLASSPATH environment variable can be modified with these commands:CLASSPATH = path1:path2:... export CLASSPATH
- Set the classpath at runtime. There are several possible ways of doing this:
- Use the -classpath option:
javac -classpath ".:/chilkatJava/chilkat.jar" Test.java java -classpath ".:/chilkatJava/chilkat.jar" Test
- Use the -Djava.class.path system property:
javac -Djava.class.path=.:/chilkatJava/chilkat.jar Test.java java -Djava.class.path=.:/chilkatJava/chilkat.jar Test
- Use the -classpath option: