设置多个系统属性Java命令行 [英] Set multiple system properties Java command line

查看:133
本文介绍了设置多个系统属性Java命令行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有更容易的方法在命令行上指定多个系统属性到Java程序,而不是多个-D语句?

Is there an easier way to specify multiple System Properties on the command line to a Java program rather than having multiple -D statements?

尝试避免这种情况: / p>

Trying to avoid this:

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

我曾经看过一个使用 -D

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.

推荐答案

答案是否定的。你可能已经看到一个例子,有人会设置像:

Answer is NO. You might have seen an example where somebody would have set something like :

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

然后应用程序将解析 Arguments 属性字符串获取单个值。
main 中,您可以获取键值(假设输入格式是保证的):

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]);
    }
}

此外, -D 应该在main类之前,或者在java命令行中的 jar 文件。示例: java -DArguments = a = 1,b = 2,c = 3,d = 4,e = cow MainClass

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

这篇关于设置多个系统属性Java命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆