eclipse 程序参数和 VM 参数有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5751851/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 16:13:04  来源:igfitidea点击:

What's the difference between program arguments and VM arguments?

javaeclipse

提问by user705414

I found only when I put -Dcontext=webinto VM arguments, the value can be read by System.getpropertymethod. I am wondering what's the difference between those two?

我发现只有当我放入-Dcontext=webVM参数时,才能通过System.getproperty方法读取该值。我想知道这两者有什么区别?

回答by Chris Thompson

Program argumentsare arguments passed to your program and available in the argsarray of your main method

程序参数是传递给程序的参数,可在args主方法的数组中使用

 public static void main(String[] args)

VM argumentsare passed to the virtual machine and are designed to instruct the VM to do something. You can do things like control the heap size, etc. They can be accessed by your program via a call to System.getProperty()as you described.

VM 参数传递给虚拟机,旨在指示 VM 执行某些操作。您可以执行诸如控制堆大小等操作。您的程序可以System.getProperty()按照您的描述通过调用来访问它们。

回答by Rajeev Rathor

enter image description here

在此处输入图片说明

Program Argument:Program arguments are arguments that are passed to your application, which are accessible via the "args" String array parameter of your main method.

程序参数:程序参数是传递给应用程序的参数,可通过主方法的“args”字符串数组参数访问。

VM Argument:VM arguments are environment or system argument that needed by JVM to execute the program. VM arguments are read from system property as below java instruction.

VM 参数:VM 参数是 JVM 执行程序所需的环境或系统参数。VM 参数从系统属性中读取,如下 java 指令。

System.getProperty(sysProp1)

System.getProperty(sysProp1)

Code Snippet:

代码片段:

public static void main(String[] args) {
    String sysProp1 = "sysProp1";
    System.out.println("\t System Propery Name:" + sysProp1 + ", Value:" + System.getProperty(sysProp1));
    System.out.println("\t Program Variable Test Propery Name:" + args[0]);
}

There are Two way to pass these two params values.

有两种方法可以传递这两个参数值。

From Eclipse:

从 Eclipse

As shown in the figure above

如上图所示

Command Line Argument:

命令行参数

 java -cp -DsysProp1=testing123456 projectJar-2.0-SNAPSHOT-jar-with-dependencies.jar 123

For a better presentation, in multiple lines

为了更好的演示,多行

 java -cp 
      -DsysProp1=testing123456 
      projectJar-2.0-SNAPSHOT-jar-with-dependencies.jar 
      123

回答by Aravind Yarram

Program args are available via the args [] of your main(String args[]) method

程序参数可通过 main(String args[]) 方法的 args [] 获得

回答by Vladimir Dyuzhev

Program arguments go into main() method:

程序参数进入 main() 方法:

public static void main(String[] args) // here

回答by TTDS

  • Program arguments - arguments which we normally pass into our program. This type parameters can be accessed using "args" String array in the main method.
  • VM arguments - arguments which are passed into the Java interpreter.
  • 程序参数 - 我们通常传递到程序中的参数。可以在 main 方法中使用“args”字符串数组访问此类型参数。
  • VM 参数 - 传递到 Java 解释器的参数。