众包常见 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(J2ME、Android、GCJ、OpenJDK、Apache Harmony 等)和 JVM 上的通用语言(Groovy、Scala、JRuby 等)应该特别有效。
现任领导者:
- rsp 19 个已发现属性
- Boris 14 个发现的属性
- Joa Ebert 发现了 8 个属性
- Suraj Chandran 1 发现了属性
顺便说一句,我计划将最终结果作为 Maven 工件发布,并在我有足够的输入后立即将其上传到中央存储库。
更新:公共存储库,终于
SystemProperty.java 现已在 GitHub 上提供,作为 molindo-utils 项目。 molindo-utils 目前可作为 1.0-通过 Sonatype 的 OSS 存储库进行快照。一旦准备好发布,它也会同步到 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>
I've been inspired by another question: Best Practice for Using Java System Properties
I'm currently looking for a complete list of Java system properties and possible values. I'm working on a simple class to simplify use of them (If you're interested, get the source and background info (my blog)). With this class, I try to provide the following:
- simple and consistent access to Java system properties (no String constants)
- full documentation of available properties and their possible values – within my IDE (i.e. auto-completion, inline Javadoc)
- fix inconsistencies in returned values and/or naming
- make sure that java.io.tmpdir exists – acutally that’s the main reason why I’m doing all this :)
To get full documentation and a complete list of available properties (even those where availability is heavily JVM-dependent), I'd like you to download the source, run it and post your results. I'll update the class accordingly and keep it available at the given location. Hopefully, it will ease live of some of you out there :)
Edit:
I'm not looking for standard properties as described by System.getProperties() or all properties that are available on my system. I'm trying to create a comprehensive list of system properties - even those that are vendor, jvm or version related - those that aren't guaranteed to exist and whose documentation is sparse or hard to find. Properties like
- sun.desktop (Linux only, e.g. "gnome"),
- awt.toolkit (Mac only, e.g. apple.awt.CToolkit)
- sun.cpu.endian (Sun JVMs only)
- ...
I'd love to get others to run my code and post their results in order to compile a comprehensive list (with extensive documentation of properties and their possible values) in the form of a Java enum that's easy to use e.g.:
String file = SystemProperty.JAVA_IO_TMPDIR + "file.txt";
instead of
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";
So please run that code and post your findings. Here is a simple script to get you started:
#!/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
(I know this isn't a real question but rather a crowd sourcing thing. I hope nobody minds)
Bounty:
As there is no correct answer to this question, the bounty will be awarded to the person who discovers most new system properties. As a hint: testing non-standard JVMs (J2ME, Android, GCJ, OpenJDK, Apache Harmony, ...) and common languages on top of the JVM (Groovy, Scala, JRuby, ..) should be especially yielding.
Current leaders:
- rsp 19 discovered properties
- Boris 14 discovered properties
- Joa Ebert 8 discovered properties
- Suraj Chandran 1 discovered property
Btw, I'm planning to release the final result as a Maven artifact and upload it to the central repository as soon as I have enough input.
UPDATE: Public Repository, finally
SystemProperty.java is now available on GitHub, as part of the molindo-utils project. molindo-utils is currently available as 1.0-SNAPSHOT through Sonatype's OSS repository. As soon as it's ready for release, it will be synchronized to Maven central as well.
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
来自 System.getProperties 的 javadoc ,仅保证这些:
From the javadoc of System.getProperties, only these are guaranteed:
以下是 64 位 Linux (Fedora 11)、Sun Java 的输出:
并且,只是为了好玩,使用 gcj java 运行时的同一系统的输出:
Here's the output from a 64-bit Linux (Fedora 11), Sun Java:
And, just for fun, the output from the same system using the gcj java runtime:
Windows 工作站:
CentOS 工作站:
Windows workstation:
CentOS workstation:
好主意,这是我的输出
Mac OS X v10.6.2 (Snow Leopard)
Nice idea, here's my output
Mac OS X v10.6.2 (Snow Leopard)
操作系统 AIX 5.3,Java 版本:
SystemProperty 输出:
OS AIX 5.3, Java version:
SystemProperty output:
列出您的所有信息:
List all your by:
JRockit
Apache Harmony
JRockit
Apache Harmony
你今天错过了一个非常重要的属性:“sun.awt.exception.handler”
它有助于捕获 evt 线程上的异常。
you missing one very important Property today: "sun.awt.exception.handler"
it helps to catch exceptions on the evt-thread..