在运行时获取 JAVA_OPTS [英] get JAVA_OPTS at runtime

查看:52
本文介绍了在运行时获取 JAVA_OPTS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序部署在 Tomcat 上,我在 /etc/default/tomcat7 中配置了 JAVA_OPTS 环境变量.

My app is deployed on Tomcat and I've configured the JAVA_OPTS environment variable in /etc/default/tomcat7.

似乎有一百万个不同的地方可以将这些变量提供给 Tomcat,所以我想检查我提供的值是否是实际使用的值.有什么我可以在运行时检查以确定这个变量的值.我检查了 System.getProperties(),但它似乎不存在.

There seem to be a million different places where these variables can be provided to Tomcat, so I want to check that the values I'm providing are what's actually being used. Is there something I can inspect at runtime to determine the value of this variable. I checked System.getProperties(), but it doesn't seem to be there.

推荐答案

如果您正在寻找只是属性覆盖和 JVM 参数,您可以使用 RuntimeMXBean:

If you're looking for just the property overrides and JVM arguments, you can use RuntimeMXBean:

RuntimeMXBean mxBean = ManagementFactory.getRuntimeMXBean();
System.out.println(mxBean.getInputArguments());

例如,使用以下命令行运行:

For example, running with the following command-line:

java -Xms512m -Xmx1024m -Dtest.prop=foo com.example.sandbox.RuntimeMXBeanExample

我得到以下输出:

[-Xms512m, -Xmx1024m, -Dtest.prop=foo]

请注意,这包括传递给 main() 方法的参数.

Note that this does not include arguments passed to the main() method.

这篇关于在运行时获取 JAVA_OPTS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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