从命令行读取Java系统属性 [英] Reading Java system properties from command line

查看:245
本文介绍了从命令行读取Java系统属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有更好的方法从命令行打印系统属性?由于我们可以设置属性,例如

Is there a better way to print system properties from command line? As we can set the property e.g.

 java  -D<name>=<value>  //set a system property

是否无需编写课程来做到这一点?

Without writing a class to do that?

如果不可能,为什么不能/不可能/很好地从命令行执行该操作?

If not possible, why is it not possible/feasible/good to do that from the command line ?

推荐答案

您可以在Hotspot JVM 1.7版及更高版本(1.6中不支持)中使用-XshowSettings标志:

You can use the -XshowSettings flag in the Hotspot JVM version 1.7 and up (not supported in 1.6):

java -XshowSettings:properties -version

自2010年底以来,OpenJDK就一直支持该标志.

OpenJDK has had support for this flag since late 2010.

http://marxsoftware.blogspot.de/2016/中看到02/hotspot-jvm-XshowSettings.html

编辑2016年12月14日

Oracle JVM附带了jcmd工具,该工具可让您查看正在运行的JVM中存在的标志.参见:

The Oracle JVM ships with the tool jcmd which allows you to see the flags present in a running JVM. See:

https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/tooldescr006.html

在此用例中,您可以使用:

For this use case, you could use:

jcmd <pid> VM.system_properties

但是,还有许多其他有用的命令.例如:

But there are also many other useful commands. For example:

jcmd <pid> VM.flags
jcmd <pid> VM.command_line
jcmd <pid> GC.run 

这篇关于从命令行读取Java系统属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆