문제

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