• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

getting jvm args passed on command line

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

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?


Thanks,
Preethi
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
perhaps, main method's argument?
 
Ranch Hand
Posts: 227
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Aditya Jha wrote:I believe JVM arguments (such as -Xms) are not part of the main method arguments.


true . I just thought of passing the same values as arguments. so that he can identifies them in list
some thing like:
java -Da=x;-Db=y;-Xms= c Program a b -Xms=c

 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic