0

I need to read the value of the parameter -javaagent at runtime. How do I access this value programmatically?

GreenSaguaro
  • 2,470
  • 2
  • 20
  • 31
  • Not exactly a duplicate, but your question is covered by [this more general question](http://stackoverflow.com/questions/1490869/how-to-get-vm-arguments-from-inside-of-java-application) (and the groovy version is more concise) – Hugues M. May 02 '17 at 20:16

1 Answers1

2

You could do this using the JVM's RuntimeMXBean:

prefix = '-javaagent:'
javaAgentValue = java.lang.management.ManagementFactory.runtimeMXBean.inputArguments.find{ it.startsWith(prefix)} ?.substring(prefix.size())
Hugues M.
  • 18,691
  • 5
  • 30
  • 60