是否有一个参考页面列出了Java System.getProperty(key)
方法始终接受的所有标准属性键?
我不是指可以由java命令的用户设置的系统属性(这将是无限列表),而是指运行时自行设置的属性(例如java.version
,{{1等等)。
答案 0 :(得分:17)
也许也有帮助:
显示JVM选择的有效属性值:
java -XshowSettings:all
答案 1 :(得分:14)
赞:https://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html? 我说Oracle会有一个列表
更新(从上面的链接复制):
"file.separator" Character that separates components of a file path. This is "/" on UNIX and "\" on Windows.
"java.class.path" Path used to find directories and JAR archives containing class files. Elements of the class path are separated by a platform-specific character specified in the path.separator property.
"java.home" Installation directory for Java Runtime Environment (JRE)
"java.vendor" JRE vendor name
"java.vendor.url" JRE vendor URL
"java.version" JRE version number
"line.separator" Sequence used by operating system to separate lines in text files
"os.arch" Operating system architecture
"os.name" Operating system name
"os.version" Operating system version
"path.separator" Path separator character used in java.class.path
"user.dir" User working directory
"user.home" User home directory
"user.name" User account name
来自https://docs.oracle.com/javase/8/docs/api/java/lang/System.html
的更完整列表java.version Java Runtime Environment version
java.vendor Java Runtime Environment vendor
java.vendor.url Java vendor URL
java.home Java installation directory
java.vm.specification.version Java Virtual Machine specification version
java.vm.specification.vendor Java Virtual Machine specification vendor
java.vm.specification.name Java Virtual Machine specification name
java.vm.version Java Virtual Machine implementation version
java.vm.vendor Java Virtual Machine implementation vendor
java.vm.name Java Virtual Machine implementation name
java.specification.version Java Runtime Environment specification version
java.specification.vendor Java Runtime Environment specification vendor
java.specification.name Java Runtime Environment specification name
java.class.version Java class format version number
java.class.path Java class path
java.library.path List of paths to search when loading libraries
java.io.tmpdir Default temp file path
java.compiler Name of JIT compiler to use
java.ext.dirs Path of extension directory or directories Deprecated. This property, and the mechanism which implements it, may be removed in a future release.
os.name Operating system name
os.arch Operating system architecture
os.version Operating system version
file.separator File separator ("/" on UNIX)
path.separator Path separator (":" on UNIX)
line.separator Line separator ("\n" on UNIX)
user.name User's account name
user.home User's home directory
user.dir User's current working directory
虽然有些重复,但我认为前者的描述比后者更具信息性。后者列出了28个属性,而如果我打印所有属性,我的jvm以56响应,28中没有列出包括sun.*
(12),*.awt.*
(3),10个用户中的7个属性(country.format, country, script, variant, timezone, language, language.format
)
答案 2 :(得分:0)
要获得更好的打印输出方式,可以使用以下代码。请注意,此代码在环境和编程语言Processing中完全可用。 (是的,它是基于Java的)
String Junk = System.getProperties().toString();
Junk = Junk.replace("}", "").replace("{", "");
String Separated [] = split(Junk, ", ");
for(int S = 0; S < Separated.length; S ++) {
String splitFurther [] = split(Separated [S], "=");
println("Key: " + splitFurther [0] + "\n\tProperty: " + splitFurther [1]);
}
希望它有所帮助。 ;)
答案 3 :(得分:0)
您可以使用以下代码
在控制台上显示所有属性及其设置 //Properties inherits form Hashtable and holds the
//Information of what the Propertie is called (key)
//and what the Propertie really is (value)
Properties props = System.getProperties();
//We want to loop through the entrys using the Keyset
Set<object> propKeySet = props.keySet();
for (Object singleKey : propKeySet) {
System.out.println(singleKey += props.getProperty((String) singleKey));
}
您可以在http://javacodingnerd.blogspot.de/2017/03/java-how-to-gather-system-properties.html
找到示例答案 4 :(得分:-1)
您可以使用此代码获取系统属性:
import java.util.Properties;
import java.util.Enumeration;
Properties props = System.getProperties();
Enumeration propNames = props.propertyNames();
for (; propNames.hasMoreElements();) {
String key = propNames.nextElement().toString();
System.out.println(key + " : " + props.getProperty(key));
}
您还可以从System.getEnv()获取环境信息。