There are three ways to set Classpath.
1. Using command
Windows:
javac -cp path_1;path_2 fileName.java
java -cp path_1;path_2;. fileName
the dot , "." , means that we want to find file in current file folder.
Linux:
javac -cp path_1:path_2 fileName.java
java -cp path_1:path_2:. fileName
The separation sybmol is different between Windows and Linux .
In windows , the separation symbol is semicolon ; .
but the separation symbol is colon : in Linux environment.
if the jar file in MyLibrary.jar , and there are a directory , MyLib , in the MyLibrary.jar ,
we should import MyLib.*;
and the command for compile is : javac -cp MyLibrary.jar program.java.
( the jar file and the program.java are in the same directory now)
2. Set Classpath variable
在windows 控制台 / 系統 / 環境變數下 , 設定CLASSPATH變數 , 並將jar file的路徑輸入到CLASSPATH variable中.
3. using Java property file
留言列表