아래와 같이 shell 변수 및 command line argument를 가져 올 수 있다.
public class Tester {
/**
* @param args
*/
public static void main(String[] args) {
// -Dname=value, -Dv1=mulder -Dv2=scully
System.out.println("v1:"+System.getProperty("v1"));
System.out.println("v2:"+System.getProperty("v2"));
// First parameter argument Index = 0
for(int i=0; i<args.length; i++) {
System.out.println("["+i+"]:"+args[i]);
}
}
}
--------------------
output
--------------------
v1:mulder
v2:scully
[0]:1
[1]:2
[2]:3
[3]:4
[4]:5