Question

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!

Was it helpful?

Solution

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"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top