众包常见 Java 系统属性和已知值的完整列表

我受到另一个问题的启发:使用Java系统属性的最佳实践

我目前正在寻找Java系统属性和可能值的完整列表。我正在开发一个简单的类来简化它们的使用(如果您有兴趣,请获取源代码背景信息(我的博客))。对于此类,我尝试提供以下内容:

  • 简单一致地访问 Java 系统属性(无字符串常量)
  • 可用属性及其可能值的完整文档 - 在我的IDE中(即自动完成,内联Javadoc)
  • 修复返回值和/或命名中的不一致
  • 确保java.io.tmpdir存在 - 从表面上看,这就是我做所有这些:)的主要原因

为了获得完整的文档和可用属性的完整列表(即使是那些可用性严重依赖于JVM的属性),我希望您下载源代码,运行它并发布您的结果。我将相应地更新类,并使其在给定位置保持可用。希望它能让你们中的一些人的生活变得轻松:)

编辑:

我不是在寻找System.getProperties()中描述的标准属性或系统上可用的所有属性。我正在尝试创建一个全面的系统属性列表 - 即使是那些与供应商,jvm或版本相关的属性 - 那些不能保证存在并且其文档稀疏或难以找到的属性。像这样的属性

  • sun.desktop(仅限 Linux,例如 “gnome”),
  • awt.toolkit (仅限 Mac,例如 apple.awt.CToolkit)
  • sun.cpu.endian (僅限 Sun JVM)
  • ...

我很想让其他人运行我的代码并发布他们的结果,以便以易于使用的Java枚举的形式编译一个全面的列表(包含属性及其可能值的大量文档),例如:

String file = SystemProperty.JAVA_IO_TMPDIR + "file.txt";

而不是

String tmp = System.getProperty("java.io.tmpdir");
if (!tmp.endsWith(File.separator)
    tmp += File.separator;
new File(tmp).mkdirs(); // make sure tmp exists
String file = tmp + "file.txt";

因此,请运行该代码并发布您的发现。下面是一个简单的脚本,可帮助您入门:

#!/bin/bash
# download and run
# you should really look at the code first, as you can't be sure
# that I'm a trustworthy guy ;)
wget -N http://techblog.molindo.at/files/SystemProperty.java
javac SystemProperty.java
java SystemProperty

(我知道这不是一个真正的问题,而是一个众包的事情。我希望没有人介意)

赏金:

由于这个问题没有正确的答案,赏金将奖励给发现大多数新系统属性的人。作为提示:在JVM(Groovy,Scala,JRuby,.)之上测试非标准JVM(J2ME,Android,GCJ,OpenJDK,Apache Harmony等)和通用语言(Groovy,Scala,JRuby,..)应该特别屈服。

现任领导:

  1. rsp 19已找到的属性
  2. 鲍里斯 14已发现住宿
  3. 若亚埃伯特 8已发现住宿
  4. 苏拉杰钱德兰 1发现住宿

顺便说一句,我计划将最终结果作为Maven工件发布,并在我有足够的输入后立即将其上传到中央存储库。

更新:公共存储库,终于

SystemProperty.java现已在GitHub上提供,作为molindo-utils项目的一部分。molindo-utils目前通过Sonatype的OSS存储库以1.0-SNAPSHOT的形式提供。一旦它准备好发布,它也将被同步到Maven中心。

<repositories>
  <repository>
    <id>oss.sonatype.org</id>
    <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
    <releases><enabled>false</enabled></releases>
    <snapshots><enabled>true</enabled></snapshots>
  </repository>
</repositories>

<dependencies>
  <dependency>
    <groupId>at.molindo</groupId>
    <artifactId>molindo-utils</artifactId>
    <version>1.0-SNAPSHOT</version>
  </dependency>
</dependencies>

答案 1

System.getProperties 的 javadoc 中,只有这些可以保证:

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 
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 

答案 2

以下是 64 位 Linux (Fedora 11) Sun Java 的输出:

FILE_ENCODING: file.encoding=UTF-8 (read-only)
FILE_ENCODING_PKG: file.encoding.pkg=sun.io (read-only)
FILE_SEPARATOR: file.separator=/ (read-only)
JAVA_AWT_GRAPHICSENV: java.awt.graphicsenv=sun.awt.X11GraphicsEnvironment (read-only)
JAVA_AWT_PRINTERJOB: java.awt.printerjob=sun.print.PSPrinterJob (read-only)
JAVA_CLASS_PATH: java.class.path=. (read-only)
JAVA_CLASS_VERSION: java.class.version=50.0 (read-only)
JAVA_ENDORSED_DIRS: java.endorsed.dirs=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/endorsed (read-only)
JAVA_EXT_DIRS: java.ext.dirs=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/ext:/usr/java/packages/lib/ext (read-only)
JAVA_HOME: java.home=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre (read-only)
JAVA_IO_TMPDIR: java.io.tmpdir=/tmp/
JAVA_LIBRARY_PATH: java.library.path=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/amd64/server:/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/amd64:/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib (read-only)
JAVA_RUNTIME_NAME: java.runtime.name=OpenJDK Runtime Environment (read-only)
JAVA_RUNTIME_VERSION: java.runtime.version=1.6.0_0-b16 (read-only)
JAVA_SPECIFICATION_NAME: java.specification.name=Java Platform API Specification (read-only)
JAVA_SPECIFICATION_VENDOR: java.specification.vendor=Sun Microsystems Inc. (read-only)
JAVA_SPECIFICATION_VERSION: java.specification.version=1.6 (read-only)
JAVA_VERSION: java.version=1.6.0_0 (read-only)
JAVA_VENDOR: java.vendor=Sun Microsystems Inc. (read-only)
JAVA_VENDOR_URL: java.vendor.url=http://java.sun.com/ (read-only)
JAVA_VENDOR_URL_BUG: java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi (read-only)
JAVA_VM_INFO: java.vm.info=mixed mode (read-only)
JAVA_VM_NAME: java.vm.name=OpenJDK 64-Bit Server VM (read-only)
JAVA_VM_SPECIFICATION_NAME: java.vm.specification.name=Java Virtual Machine Specification (read-only)
JAVA_VM_SPECIFICATION_VENDOR: java.vm.specification.vendor=Sun Microsystems Inc. (read-only)
JAVA_VM_SPECIFICATION_VERSION: java.vm.specification.version=1.0 (read-only)
JAVA_VM_VERSION: java.vm.version=14.0-b16 (read-only)
JAVA_VM_VENDOR: java.vm.vendor=Sun Microsystems Inc. (read-only)
LINE_SEPARATOR: line.separator=
 (read-only)
OS_NAME: os.name=Linux (read-only)
OS_ARCH: os.arch=amd64 (read-only)
OS_VERSION: os.version=2.6.30.9-96.fc11.x86_64 (read-only)
PATH_SEPARATOR: path.separator=: (read-only)
SUN_ARCH_DATA_MODEL: sun.arch.data.model=64 (read-only)
SUN_BOOT_CLASS_PATH: sun.boot.class.path=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/resources.jar:/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/rt.jar:/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/sunrsasign.jar:/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/jsse.jar:/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/jce.jar:/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/charsets.jar:/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/rhino.jar:/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/classes (read-only)
SUN_BOOT_LIBRARY_PATH: sun.boot.library.path=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/amd64 (read-only)
SUN_CPU_ENDIAN: sun.cpu.endian=little (read-only)
SUN_CPU_ISALIST: sun.cpu.isalist= (read-only)
SUN_IO_UNICODE_ENCODING: sun.io.unicode.encoding=UnicodeLittle (read-only)
SUN_JAVA_LAUNCHER: sun.java.launcher=SUN_STANDARD (read-only)
SUN_JNU_ENCODING: sun.jnu.encoding=UTF-8 (read-only)
SUN_MANAGEMENT_COMPILER: sun.management.compiler=HotSpot 64-Bit Server Compiler (read-only)
SUN_OS_PATCH_LEVEL: sun.os.patch.level=unknown (read-only)
USER_COUNTRY: user.country=US (read-only)
USER_DIR: user.dir=/disk/a/3/home/bc (read-only)
USER_HOME: user.home=/home/bc (read-only)
USER_LANGUAGE: user.language=en (read-only)
USER_NAME: user.name=bc (read-only)
USER_TIMEZONE: user.timezone= (read-only)
SUN_DESKTOP: sun.desktop=gnome (read-only)
AWT_NATIVE_DOUBLE_BUFFERING: awt.nativeDoubleBuffering=null (read-only)
AWT_TOOLKIT: awt.toolkit=null (read-only)
FTP_NON_PROXY_HOSTS: ftp.nonProxyHosts=null (read-only)
GOPHER_PROXY_SET: gopherProxySet=null (read-only)
HTTP_NON_PROXY_HOSTS: http.nonProxyHosts=null (read-only)
MRJ_VERSION: mrj.version=null (read-only)
SOCKS_NON_PROXY_HOSTS: socksNonProxyHosts=null (read-only)


### UNKNOWN
AWT_NATIVE_DOUBLE_BUFFERING: awt.nativeDoubleBuffering=null (read-only)
AWT_TOOLKIT: awt.toolkit=null (read-only)
FTP_NON_PROXY_HOSTS: ftp.nonProxyHosts=null (read-only)
GOPHER_PROXY_SET: gopherProxySet=null (read-only)
HTTP_NON_PROXY_HOSTS: http.nonProxyHosts=null (read-only)
MRJ_VERSION: mrj.version=null (read-only)
SOCKS_NON_PROXY_HOSTS: socksNonProxyHosts=null (read-only)


### MISSING
user.zoneinfo.dir=/usr/share/javazi


### PLEASE POST THIS AT http://j.mp/props0 or http://j.mp/props1
    /**
     * Linux only: known values: /usr/share/javazi
     */
    USER_ZONEINFO_DIR("user.zoneinfo.dir"),

而且,只是为了好玩,使用gcj java运行时的同一系统的输出:

FILE_ENCODING: file.encoding=UTF-8 (read-only)
FILE_ENCODING_PKG: file.encoding.pkg=null (read-only)

FILE_SEPARATOR: file.separator=/ (read-only)
JAVA_AWT_GRAPHICSENV: java.awt.graphicsenv=null (read-only)
JAVA_AWT_PRINTERJOB: java.awt.printerjob=null (read-only)
JAVA_CLASS_PATH: java.class.path=. (read-only)
JAVA_CLASS_VERSION: java.class.version=49.0 (read-only)
JAVA_ENDORSED_DIRS: java.endorsed.dirs=null (read-only)
JAVA_EXT_DIRS: java.ext.dirs=/usr/share/java/ext (read-only)
JAVA_HOME: java.home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre (read-only)
JAVA_IO_TMPDIR: java.io.tmpdir=/tmp/
JAVA_LIBRARY_PATH: java.library.path=/usr/lib64/gcj-4.4.1 (read-only)
JAVA_RUNTIME_NAME: java.runtime.name=null (read-only)
JAVA_RUNTIME_VERSION: java.runtime.version=1.5.0 (read-only)
JAVA_SPECIFICATION_NAME: java.specification.name=Java(tm) Platform API Specification (read-only)
JAVA_SPECIFICATION_VENDOR: java.specification.vendor=Sun Microsystems Inc. (read-only)
JAVA_SPECIFICATION_VERSION: java.specification.version=1.5 (read-only)
JAVA_VERSION: java.version=1.5.0 (read-only)
JAVA_VENDOR: java.vendor=Free Software Foundation, Inc. (read-only)
JAVA_VENDOR_URL: java.vendor.url=http://gcc.gnu.org/java/ (read-only)
JAVA_VENDOR_URL_BUG: java.vendor.url.bug=null (read-only)
JAVA_VM_INFO: java.vm.info=GNU libgcj 4.4.1 20090725 (Red Hat 4.4.1-2) (read-only)
JAVA_VM_NAME: java.vm.name=GNU libgcj (read-only)
JAVA_VM_SPECIFICATION_NAME: java.vm.specification.name=Java(tm) Virtual Machine Specification (read-only)
JAVA_VM_SPECIFICATION_VENDOR: java.vm.specification.vendor=Sun Microsystems Inc. (read-only)
JAVA_VM_SPECIFICATION_VERSION: java.vm.specification.version=1.0 (read-only)
JAVA_VM_VERSION: java.vm.version=4.4.1 20090725 (Red Hat 4.4.1-2) (read-only)
JAVA_VM_VENDOR: java.vm.vendor=Free Software Foundation, Inc. (read-only)
LINE_SEPARATOR: line.separator=
 (read-only)
OS_NAME: os.name=Linux (read-only)
OS_ARCH: os.arch=x86_64 (read-only)
OS_VERSION: os.version=2.6.30.9-96.fc11.x86_64 (read-only)
PATH_SEPARATOR: path.separator=: (read-only)
SUN_ARCH_DATA_MODEL: sun.arch.data.model=null (read-only)
SUN_BOOT_CLASS_PATH: sun.boot.class.path=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre/lib/rt.jar (read-only)
SUN_BOOT_LIBRARY_PATH: sun.boot.library.path=null (read-only)
SUN_CPU_ENDIAN: sun.cpu.endian=null (read-only)
SUN_CPU_ISALIST: sun.cpu.isalist=null (read-only)
SUN_IO_UNICODE_ENCODING: sun.io.unicode.encoding=null (read-only)
SUN_JAVA_LAUNCHER: sun.java.launcher=null (read-only)
SUN_JNU_ENCODING: sun.jnu.encoding=null (read-only)
SUN_MANAGEMENT_COMPILER: sun.management.compiler=null (read-only)
SUN_OS_PATCH_LEVEL: sun.os.patch.level=null (read-only)
USER_COUNTRY: user.country=null (read-only)
USER_DIR: user.dir=/disk/a/3/home/bc (read-only)
USER_HOME: user.home=/home/bc (read-only)
USER_LANGUAGE: user.language=en (read-only)
USER_NAME: user.name=bc (read-only)
USER_TIMEZONE: user.timezone=null (read-only)
SUN_DESKTOP: sun.desktop=null (read-only)
AWT_NATIVE_DOUBLE_BUFFERING: awt.nativeDoubleBuffering=null (read-only)
AWT_TOOLKIT: awt.toolkit=null (read-only)
FTP_NON_PROXY_HOSTS: ftp.nonProxyHosts=null (read-only)
GOPHER_PROXY_SET: gopherProxySet=null (read-only)
HTTP_NON_PROXY_HOSTS: http.nonProxyHosts=null (read-only)
MRJ_VERSION: mrj.version=null (read-only)
SOCKS_NON_PROXY_HOSTS: socksNonProxyHosts=null (read-only)


### UNKNOWN
FILE_ENCODING_PKG: file.encoding.pkg=null (read-only)
JAVA_AWT_GRAPHICSENV: java.awt.graphicsenv=null (read-only)
JAVA_AWT_PRINTERJOB: java.awt.printerjob=null (read-only)
JAVA_ENDORSED_DIRS: java.endorsed.dirs=null (read-only)
JAVA_RUNTIME_NAME: java.runtime.name=null (read-only)
JAVA_VENDOR_URL_BUG: java.vendor.url.bug=null (read-only)
SUN_ARCH_DATA_MODEL: sun.arch.data.model=null (read-only)
SUN_BOOT_LIBRARY_PATH: sun.boot.library.path=null (read-only)
SUN_CPU_ENDIAN: sun.cpu.endian=null (read-only)
SUN_CPU_ISALIST: sun.cpu.isalist=null (read-only)
SUN_IO_UNICODE_ENCODING: sun.io.unicode.encoding=null (read-only)
SUN_JAVA_LAUNCHER: sun.java.launcher=null (read-only)
SUN_JNU_ENCODING: sun.jnu.encoding=null (read-only)
SUN_MANAGEMENT_COMPILER: sun.management.compiler=null (read-only)
SUN_OS_PATCH_LEVEL: sun.os.patch.level=null (read-only)
USER_COUNTRY: user.country=null (read-only)
USER_TIMEZONE: user.timezone=null (read-only)
SUN_DESKTOP: sun.desktop=null (read-only)
AWT_NATIVE_DOUBLE_BUFFERING: awt.nativeDoubleBuffering=null (read-only)
AWT_TOOLKIT: awt.toolkit=null (read-only)
FTP_NON_PROXY_HOSTS: ftp.nonProxyHosts=null (read-only)
GOPHER_PROXY_SET: gopherProxySet=null (read-only)
HTTP_NON_PROXY_HOSTS: http.nonProxyHosts=null (read-only)
MRJ_VERSION: mrj.version=null (read-only)
SOCKS_NON_PROXY_HOSTS: socksNonProxyHosts=null (read-only)


### MISSING
gnu.classpath.home=/usr
gnu.classpath.home.url=file:///usr/lib64
gnu.classpath.version=0.98
gnu.classpath.vm.shortname=libgcj
gnu.cpu.endian=little
gnu.gcj.precompiled.db.path=/usr/lib64/gcj-4.4.1/classmap.db
gnu.gcj.progname=SystemProperty
gnu.gcj.runtime.endorsed.dirs=/usr/share/java/gcj-endorsed
gnu.gcj.user.realname=
gnu.java.util.zoneinfo.dir=/usr/share/zoneinfo
http.agent=gnu-classpath/0.98 (libgcj/4.4.1 20090725 (Red Hat 4.4.1-2))
java.fullversion=GNU libgcj 4.4.1 20090725 (Red Hat 4.4.1-2)
user.region=US


### PLEASE POST THIS AT http://j.mp/props0 or http://j.mp/props1
    /**
     * Linux only: known values: /usr
     */
    GNU_CLASSPATH_HOME("gnu.classpath.home"),
    /**
     * Linux only: known values: file:///usr/lib64
     */
    GNU_CLASSPATH_HOME_URL("gnu.classpath.home.url"),
    /**
     * Linux only: known values: 0.98
     */
    GNU_CLASSPATH_VERSION("gnu.classpath.version"),
    /**
     * Linux only: known values: libgcj
     */
    GNU_CLASSPATH_VM_SHORTNAME("gnu.classpath.vm.shortname"),
    /**
     * Linux only: known values: little
     */
    GNU_CPU_ENDIAN("gnu.cpu.endian"),
    /**
     * Linux only: known values: /usr/lib64/gcj-4.4.1/classmap.db
     */
    GNU_GCJ_PRECOMPILED_DB_PATH("gnu.gcj.precompiled.db.path"),
    /**
     * Linux only: known values: SystemProperty
     */
    GNU_GCJ_PROGNAME("gnu.gcj.progname"),
    /**
     * Linux only: known values: /usr/share/java/gcj-endorsed
     */
    GNU_GCJ_RUNTIME_ENDORSED_DIRS("gnu.gcj.runtime.endorsed.dirs"),
    /**
     * Linux only: known values: 
     */
    GNU_GCJ_USER_REALNAME("gnu.gcj.user.realname"),
    /**
     * Linux only: known values: /usr/share/zoneinfo
     */
    GNU_JAVA_UTIL_ZONEINFO_DIR("gnu.java.util.zoneinfo.dir"),
    /**
     * Linux only: known values: gnu-classpath/0.98 (libgcj/4.4.1 20090725 (Red Hat 4.4.1-2))
     */
    HTTP_AGENT("http.agent"),
    /**
     * Linux only: known values: GNU libgcj 4.4.1 20090725 (Red Hat 4.4.1-2)
     */
    JAVA_FULLVERSION("java.fullversion"),
    /**
     * Linux only: known values: US
     */
    USER_REGION("user.region"),