Is there an easier way to specify multiple System Properties on the command line to a Java program rather than having multiple -D statements?
Trying to avoid this:
java -jar -DNAME="myName" -DVERSION="1.0" -DLOCATION="home" program.jar
I thought I had seen an example of someone using one -D
and some quoted string after that, but I can't find the example again.
System properties are set on the Java command line using the -Dpropertyname=value syntax. They can also be added at runtime using System. setProperty(String key, String value) or via the various System. getProperties().
Go to the Registry Editor (Start > regedit.exe). To change existing properties double-click the appropriate value. To change additional properties, double-click options. Refer to the list of parameters in Recognized System Properties.
Answer is NO. You might have seen an example where somebody would have set something like :
-DArguments=a=1,b=2,c=3,d=4,e=cow
Then the application would parse value of Arguments
property string to get individual values. In your main
you can get the key values as(Assuming input format is guaranteed):
String line = System.getProperty("Arguments"); if(line != null) { String str[] = line.split(","); for(int i=1;i<str.length;i++){ String arr[] = str[i].split("="); System.out.println("Key = " + arr[0]); System.out.println("Value = " + arr[1]); } }
Also, the -D
should be before the main class or the jar
file in the java command line. Example : java -DArguments=a=1,b=2,c=3,d=4,e=cow MainClass
There's nothing on the Documentation that mentions about anything like that.
Here's a quote:
-Dproperty=value Set a system property value. If value is a string that contains spaces, you must enclose the string in double quotes:
java -Dfoo="some string" SomeClass
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