Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between java dashed arguments (like -D) and the without a dash?

Tags:

java

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?

like image 385
GardenMan Avatar asked Oct 28 '17 10:10

GardenMan


1 Answers

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").

like image 132
T.J. Crowder Avatar answered Nov 11 '22 03:11

T.J. Crowder