is there a faster way to retrieve a JVM Parameter in a Java Bean?

I've read about this here:

RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean(); List arguments = runtimeMxBean.getInputArguments();

but then you have to cycle on all the parameters...I think it's not so good.

For example in log4j properties you can retrieve the parameter using this notation: ${MY_JVM_PARAMETER}. Is there a similar think available in Java code?

Thanks all!

有帮助吗?

解决方案

Simple and trivial way is to use the java.lang.System#getProperty:

String prop = System.getProperty("my.property");

Assuming that you lanched your java application with a jvm param like -Dmy.property="someValue"

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top