Given the following class:
public class SpecifySystemPropertiesCommandLine {
public static void main(String[] args) {
String prop1 = System.getProperty("prop1", "defaultvalue");
String prop2 = System.getProperty("prop2", "defaultvalue");
System.out.println("prop1 = " + prop1);
System.out.println("prop2 = " + prop2);
}
}
Why does the following not work:
$ java -jar sysprop.jar -Dprop1="i can haz?"
prop1 = defaultvalue
prop2 = defaultvalue
but this works:
$ java -Dprop1="i can haz?" -jar sysprop.jar
prop1 = i can haz?
prop2 = defaultvalue
See http://docs.oracle.com/javase/6/docs/technotes/tools/windows/java.html.
Everything after the jar file name is an argument passed to the main method of your class/app.
-Dprop=val is an argument that is passed to the java process.