Saturday, February 14, 2009
Java Classpath
package com.wickedlysmart;
public class SayHello{
public void greet(){
System.out.println("Hi");
}
}
import com.wickedlysmart.SayHello;
public class SayHelloTest{
public static void main(String[] args){
SayHello sh = new SayHello();
sh.greet();
}
}
C:\JavaPractice\source\com\wickedlysmart\SayHello.java
C:\JavaPractice\source\com\wickedlysmart \TestSayHello.java
To build, from C:\JavaPractice\source:
javac -d ../classes com/wickedlysmart/SayHello.java
Then,
javac -d ../classes -classpath C:\JavaPractice\classes com/wickedlysmart/SayHelloTest.java
You can use -cp instead of -classpath
SayHelloTest.class will be created in the classes folder.
Then copy the SayHelloTest.class anywhere you like.
To execute from anywhere where the TestSayHello.class is in
the same folder as you:
java -classpath C:\JavaPractice\classes;. SayHelloTest
or,
java -cp C:\JavaPractice\classes;. SayHelloTest
Note that ; is the separator for Windows.