我受到另一个问题的启发:Best Practice for Using Java System Properties
我目前正在寻找 Java 系统属性和可能值的完整列表。我正在研究一个简单的类来简化它们的使用(如果你有兴趣,get the source 和 background info (my blog))。通过这个类(class),我尝试提供以下内容:
要获得完整的文档和可用属性的完整列表(即使是那些可用性严重依赖 JVM 的属性),我希望您能 download the source ,运行它并发布您的结果。我将相应地更新类(class)并使其在给定位置可用。希望它能让你们中的一些人轻松生活:)
编辑:
我不是在寻找 System.getProperties() 中描述的标准属性。或我的系统上可用的所有属性。我正在尝试创建一个全面的系统属性列表——即使是那些与供应商、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 之上测试非标准 JVM(J2ME、Android、GCJ、OpenJDK、Apache Harmony 等)和通用语言(Groovy、Scala、JRuby 等)应该特别有效。
现任领导人:
顺便说一句,我计划将最终结果作为 Maven 工件发布,并在我有足够的输入后立即将其上传到中央存储库。
更新:公共(public)存储库,终于
SystemProperty.java现已在 GitHub 上提供,作为 molindo-utils project 的一部分. molindo-utils 目前可用 1.0-SNAPSHOT through Sonatype's OSS repository .一旦准备好发布,它也会同步到 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>
最佳答案
来自 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
关于java - 众包常见 Java 系统属性和已知值的完整列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1803075/
我希望我的UserPrice模型的属性在它们为空或不验证数值时默认为0。这些属性是tax_rate、shipping_cost和price。classCreateUserPrices8,:scale=>2t.decimal:tax_rate,:precision=>8,:scale=>2t.decimal:shipping_cost,:precision=>8,:scale=>2endendend起初,我将所有3列的:default=>0放在表格中,但我不想要这样,因为它已经填充了字段,我想使用占位符。这是我的UserPrice模型:classUserPrice回答before_val
我有一个包含模块的模型。我想在模块中覆盖模型的访问器方法。例如:classBlah这显然行不通。有什么想法可以实现吗? 最佳答案 您的代码看起来是正确的。我们正在毫无困难地使用这个确切的模式。如果我没记错的话,Rails使用#method_missing作为属性setter,因此您的模块将优先,阻止ActiveRecord的setter。如果您正在使用ActiveSupport::Concern(参见thisblogpost),那么您的实例方法需要进入一个特殊的模块:classBlah
是否有类似“RVMuse1”或“RVMuselist[0]”之类的内容而不是键入整个版本号。在任何时候,我们都会看到一个可能包含5个或更多ruby的列表,我们可以轻松地键入一个数字而不是X.X.X。这也有助于rvmgemset。 最佳答案 这在RVM2.0中是可能的=>https://docs.google.com/document/d/1xW9GeEpLOWPcddDg_hOPvK4oeLxJmU3Q5FiCNT7nTAc/edit?usp=sharing-知道链接的任何人都可以发表评论
我有一个具有一些属性的模型:attr1、attr2和attr3。我需要在不执行回调和验证的情况下更新此属性。我找到了update_column方法,但我想同时更新三个属性。我需要这样的东西:update_columns({attr1:val1,attr2:val2,attr3:val3})代替update_column(attr1,val1)update_column(attr2,val2)update_column(attr3,val3) 最佳答案 您可以使用update_columns(attr1:val1,attr2:val2
我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/
我有这个html标记:我想得到这个:我如何使用Nokogiri做到这一点? 最佳答案 require'nokogiri'doc=Nokogiri::HTML('')您可以通过xpath删除所有属性:doc.xpath('//@*').remove或者,如果您需要做一些更复杂的事情,有时使用以下方法遍历所有元素会更容易:doc.traversedo|node|node.keys.eachdo|attribute|node.deleteattributeendend 关于ruby-Nokog
对于Rails模型,是否可以/建议让一个类的成员不持久保存到数据库中?我想将用户最后选择的类型存储在session变量中。由于我无法从我的模型中设置session变量,我想将值存储在一个“虚拟”类成员中,该成员只是将值传递回Controller。你能有这样的类(class)成员吗? 最佳答案 将非持久属性添加到Rails模型就像任何其他Ruby类一样:classUser扩展解释:在Ruby中,所有实例变量都是私有(private)的,不需要在赋值前定义。attr_accessor创建一个setter和getter方法:classUs
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www
我只想对我一直在思考的这个问题有其他意见,例如我有classuser_controller和classuserclassUserattr_accessor:name,:usernameendclassUserController//dosomethingaboutanythingaboutusersend问题是我的User类中是否应该有逻辑user=User.newuser.do_something(user1)oritshouldbeuser_controller=UserController.newuser_controller.do_something(user1,user2)我
什么是ruby的rack或python的Java的wsgi?还有一个路由库。 最佳答案 来自Python标准PEP333:Bycontrast,althoughJavahasjustasmanywebapplicationframeworksavailable,Java's"servlet"APImakesitpossibleforapplicationswrittenwithanyJavawebapplicationframeworktoruninanywebserverthatsupportstheservletAPI.ht