While reading java man
page, I found the -Dproperty=value
flag which stats that by passing this flag, it will create a system property with value = value.
I wrote a test java code:
class File{
public static void main(String[] args){
System.out.println("HOLA");
System.out.println(System.getProperty("blah"));
}
}
I compiled the same with javac File.java
and then ran with with command java File -Dblah=blah
but I got the following output
HOLA
null
and then I ran with as java -Dblah=blah File
and then I got the expected output:
HOLA
blah
The question is: Is this a bug or is this an intentional behavior. It does seem a bug because in most of the program, order doesn't matter at command line.
The -D
needs to come before the class name, because anything after the class name is regarded as an argument to the Java app itself... and the Java app may choose to do anything it likes with -D
, or any other JVM options.
Basically, the syntax is:
java [jvm-args] class-name [application-args]
See more on this question at Stackoverflow