I am passing in certain -D environment variables as VM options to a Java server application.
I need to retrieve those variables from the application, but when I use System.getProperties() I am getting all of those, plus all of the system properties defined at the operating system level, which I am not interested in.
Is there any way to just discover the -D parameters?
You can obtain it using RuntimeMXBean(The management interface for the runtime system of the Java virtual machine) like this
RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();
List<String> args = bean.getInputArguments();
Please Note that getInputArguments() Returns the input arguments passed to the Java virtual machine which does not include the arguments to the main method. This method returns an empty list if there is no input argument to the Java virtual machine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With