JVM中的系统属性system . getproperties()和环境变量system .getenv()之间有什么区别?
当前回答
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().load() methods. To get a specific system property you can use System.getProperty(String key) or System.getProperty(String key, String def). Environment variables are set in the OS, e.g. in Linux export HOME=/Users/myusername or on Windows SET WINDIR=C:\Windows etc, and, unlike properties, may not be set at runtime. To get a specific environment variable you can use System.getenv(String name).
其他回答
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().load() methods. To get a specific system property you can use System.getProperty(String key) or System.getProperty(String key, String def). Environment variables are set in the OS, e.g. in Linux export HOME=/Users/myusername or on Windows SET WINDIR=C:\Windows etc, and, unlike properties, may not be set at runtime. To get a specific environment variable you can use System.getenv(String name).
我认为两者之间的区别归结为获取途径。环境变量可以被任何进程访问,而Java系统属性只能被添加它们的进程访问。
同样,正如波西米亚所说,env变量是在操作系统中设置的(然而,它们“可以”通过Java设置),系统属性是作为命令行选项传递或通过setProperty()设置的。
推荐文章
- 在maven中安装mvn到底做什么
- 不可变与不可修改的集合
- 如何在JSON中使用杰克逊更改字段名
- GSON -日期格式
- 如何从线程捕获异常
- 无法解析主机"<URL here>"没有与主机名关联的地址
- 如何在Java中打印二叉树图?
- String.format()在Java中格式化双重格式
- com.jcraft.jsch.JSchException: UnknownHostKey
- Java中的操作符重载
- 如何加速gwt编译器?
- 在Hibernate中重新连接分离对象的正确方法是什么?
- 应该……接住环内还是环外?
- 如何格式化Joda-Time DateTime仅为mm/dd/yyyy?
- 如何在POM.xml中引用环境变量?