Set several system properties. Java command line.

Is there an easier way to specify multiple system properties on the command line for a Java program instead of having multiple -D statements?

Trying to avoid this:

java -jar -DNAME="myName" -DVERSION="1.0" -DLOCATION="home" program.jar 

It seemed to me that I saw an example of someone who used one -D and some quoted string, but I can no longer find this example.

+44
java command-line system-properties
Sep 08 2018-11-11T00:
source share
4 answers

The answer is NO. You may have seen an example where someone would install something like:

-DArguments=a=1,b=2,c=3,d=4,e=cow

The application will then analyze the value of the Arguments property string to obtain individual values. In 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]); } } 

In addition, -D must be in front of the main class or jar file on the java command line. Example: java -DArguments=a=1,b=2,c=3,d=4,e=cow MainClass

+36
Sep 16 2018-11-11T00:
source share

Instead of passing properties as an argument, you can use .properties to store them.

+13
Sep 08 '11 at 17:06
source share

There is nothing in the documentation that mentions something like that.

Here is a quote:

-D property = value Set the value of the system property. If the value is a string that contains spaces, you must enclose the string in double quotes:

java -Dfoo = "some string" SomeClass

+8
Sep 08 '11 at 16:48
source share

If the required properties need to be set on the system, then there is no option other than -D. But if you need these properties when loading the application, then loading properties through proerties files is the best option. This does not require assembly changes for a single property.

0
Aug 19 '16 at 9:55 on
source share



All Articles