JVM系統屬性(System Properties)
1.不支持通過文件查看和設置系統屬性
2.可以通過JDK自帶的工具jvisulavm.exe查看
3.可以在Java程序中使用API來查看系統屬性:
System.getProperties(),
System.getProperties(),
System.getProperty(String name),
System.getProperty(String name, String def)
Spring中的Environment.getProperty
Spring中的ConfigurableEnvironment.getSystemProperties()
4.可以在Java程序中使用API來設置系統屬性:
System.setProperty(key,value),
Spring中的Environment.getProperty
Spring中的ConfigurableEnvironment.getSystemProperties()
4.可以在Java程序中使用API來設置系統屬性:
System.setProperty(key,value),
System.setProperties(Properties props)
5.設置JVM 啟動參數-D<name>=<value>5來設置系統屬性
環境變量(System Environment Variable)
Java程序通過API System.getenv()和System.getenv(String name),以及Spring中的Environment.getProperty和ConfigurableEnvironment.getSystemEnvironment() 來獲取系統環境變量
補充:系統環境變量的查看和設置的其他方式
命令行方式
增加:set 變量名=%變量名%;變量內容
刪除:set 變量名=
修改:set 變量名=變量內容
查看:set 或 set 變量名
圖形界面方式:右擊This PC->單擊Properties->Advanced System Settings->Advanced->Environment Variables
WIN+R方式:sysdm.cpl->Advanced->Environment Variables
控制面板方式:Control Panel->System and Security->System->Advanced System Settings->Advanced->Environment Variables
JVM參數
Java運行參數和JVM參數的設置和獲取
命令行中的參數設置
java 命令的基本格式為 java [-options] class [args...],其中:
[-options] 配置 Java 系統參數
[args…] 配置 Java 運行參數
eg.java -Dfile.encoding=UTF-8 -Dmy=user Test hi a b c d。
Eclipse 中的參數設置
右擊要運行的類 -> Run As –> Run Configurations,在對話框中選擇 Arguments 選項卡,鍵入相應參數。
JVM參數的設置可以通過Tomcat的啟動腳本來設置:-Dspring.profiles.active="production"
JVM參數的設置可以通過Tomcat的啟動腳本來設置:-Dspring.profiles.active="production"
運行參數的獲取
public static void main(String[] args) throws IOException
{
for(String arg: args){
System.out.println(arg);
}
}
JVM啟動參數的獲取
List<String> list = ManagementFactory.getRuntimeMXBean().getInputArguments();
for(String jvmArg: list){
System.out.println(jvmArg);
}
JVM參數的查看:可以通過JDK自帶的工具jvisulavm.exe查看
refer to: https://blog.csdn.net/lsziri/article/details/81200334 ; https://www.cnblogs.com/flashsun/p/7246232.html ;
refer to: https://blog.csdn.net/lsziri/article/details/81200334 ; https://www.cnblogs.com/flashsun/p/7246232.html ;