Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I obtain the -D parameters passed in to Java launch

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?

like image 819
vinnygray Avatar asked Nov 01 '22 12:11

vinnygray


1 Answers

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.

like image 113
sol4me Avatar answered Nov 14 '22 02:11

sol4me