I have an application which i can launch from cmd line, and optionally that application can take some jvm args on cmd line. There is some processing I want to do by getting the list of jvm args that were passed on cmd line. I tried to use this API:
RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean();
List<String> arguments = RuntimemxBean.getInputArguments();
But this gives a list of jvm args in the env, including the ones I passed on cmd line. I am only interested in the jvm args passed on cmd line. Is there any API to get that? Or, is it something I should enhance in my application only?
Seetharaman Venkatasamy wrote:perhaps, main method's argument?
I believe JVM arguments (such as -Xms) are not part of the main method arguments.
As for the original question, the behaviour of RuntimeMXBean.getInputArguments() is JVM-implementation specific. So, I would not recommend relying on it too much. Usually, application code does not need (or care) about what JVM arguments were supplied to the runtime, and for good reason. However, if you do want to have the application behave differently in say, different memory conditions etc., there are ways to get those settings from Runtime, instead of getting JVM arguments (and parsing them etc.).
IMHO, try to get what you want directly from Runtime, instead of worrying too much about the exact JVM arguments supplied via command-line.