java有哪些来源来填充系统属性
Which are the source of java to fill system properties
通过 System.getProperty(String key) you can get the value of some java system properties, however my question is about how java fill these values, more exactly where is the source of this information. I'm looking in some places like here 但我没有找到答案。
我的问题是我正在尝试测试我的代码的某些行为,我想更改系统 属性 以获得 java 之外的 os.name
值(我知道我可以用 System.setProperty(String key, String value)
设置值但是我想在外面做),所以任何人都知道我必须改变什么才能通过 System.getProperty('os.name')
?
获得新值
谢谢!
我认为您不应该修改内置 System Properties,链接的 Java 教程说(部分)
The System
class maintains a Properties
object that describes the configuration of the current working environment.
和
Warning: Changing system properties is potentially dangerous and should be done with discretion. Many system properties are not reread after start-up and are there for informational purposes. Changing some properties may have unexpected side-effects.
终于
To modify the existing set of system properties, use System.setProperties
. This method takes a Properties
object that has been initialized to contain the properties to be set.
您可以 运行 java 使用选项 -Dos.name="XXX"
所以 System.getProperty('os.name')
将 return 'XXX'.
您可以将 VM 参数传递为
-Dos.name="Ubuntu 10.1"
如果您是 运行 Eclipse,您可以通过 运行 > 运行 配置指定值...Select 您的程序在 Java 应用程序并在“参数”选项卡中提供值。
通过 System.getProperty(String key) you can get the value of some java system properties, however my question is about how java fill these values, more exactly where is the source of this information. I'm looking in some places like here 但我没有找到答案。
我的问题是我正在尝试测试我的代码的某些行为,我想更改系统 属性 以获得 java 之外的 os.name
值(我知道我可以用 System.setProperty(String key, String value)
设置值但是我想在外面做),所以任何人都知道我必须改变什么才能通过 System.getProperty('os.name')
?
谢谢!
我认为您不应该修改内置 System Properties,链接的 Java 教程说(部分)
The
System
class maintains aProperties
object that describes the configuration of the current working environment.
和
Warning: Changing system properties is potentially dangerous and should be done with discretion. Many system properties are not reread after start-up and are there for informational purposes. Changing some properties may have unexpected side-effects.
终于
To modify the existing set of system properties, use
System.setProperties
. This method takes aProperties
object that has been initialized to contain the properties to be set.
您可以 运行 java 使用选项 -Dos.name="XXX"
所以 System.getProperty('os.name')
将 return 'XXX'.
您可以将 VM 参数传递为
-Dos.name="Ubuntu 10.1"
如果您是 运行 Eclipse,您可以通过 运行 > 运行 配置指定值...Select 您的程序在 Java 应用程序并在“参数”选项卡中提供值。