I need to read the value of the parameter -javaagent
at runtime. How do I access this value programmatically?
Asked
Active
Viewed 203 times
0

GreenSaguaro
- 2,968
- 2
- 22
- 41
-
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 Answers
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.
- 19,846
- 6
- 37
- 65