When we launch jar file by command line
$ java -jar someJar.jar arg1 arg2
We can pass argument by just adding arguments by space. But sometimes I faced with the arguments those start with dash like -Darg1, -Darg2. What is the difference between them?
Without the -D
, you're creating arguments that will be passed to main
in its string array. With the -D
, you're defining a system property which is accessibe from System.getProperties
and System.getProperty
. Some system properties have predefined meanings, such as user.dir
which defines the user's home directory. More about "system properties" here.
This is documented in the tools documentation for the java
tool:
-Dproperty=value
Sets a system property value. The property variable is a string with no spaces that represents the name of the property. The value variable is a string that represents the value of the property. If value is a string with spaces, then enclose it in quotation marks (for example
-Dfoo="foo bar"
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With