0

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!

Community
  • 1
  • 1
user2010955
  • 3,871
  • 7
  • 34
  • 53

1 Answers1

1

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"

tmarwen
  • 15,750
  • 5
  • 43
  • 62
  • I tried but it doesn't work, it returns me a null value. And yes, I've used -Dmyproperty=someValue. I'm noticing that someValue is not between quotes, it could be that? – user2010955 Mar 12 '14 at 11:52
  • Nice to hear that and maybe you can paste the tecik so it is made viewble for others, what was the problem already? – tmarwen Mar 12 '14 at 12:18