accessing VM command line from code

Discussion in 'Java' started by angelochen960@gmail.com, Mar 17, 2009.

  1. Guest

    Hi,

    Is there a way to access VM command line parameters from a java code,
    particularly a servlet ? Thanks

    A.c
    , Mar 17, 2009
    #1
    1. Advertising

  2. Hi there,

    <> wrote
    > Is there a way to access VM command line parameters from a java code,
    > particularly a servlet ? Thanks
    >

    You can use Runtime.exec:
    http://java.sun.com/javase/6/docs/api/java/lang/Runtime.html

    and execute the command "$JAVA_HOME/bin/jps -v"

    then you have to:

    1) Find the appropriate Servlet process e.g. the String contains tomcat
    1) parse the output for all command line parameters ...

    HTH,
    regards,
    Giovanni
    Giovanni Azua, Mar 17, 2009
    #2
    1. Advertising

  3. if you know the process id beforehand and assuming Unix environment then you
    only need to execute:

    "$JAVA_HOME/bin/jps -v | grep <pid>"

    jps also works remotely so you can specify the remote host to connect to.

    HTH,
    regards,
    Giovanni
    Giovanni Azua, Mar 17, 2009
    #3
  4. Arne Vajhøj Guest

    wrote:
    > Is there a way to access VM command line parameters from a java code,
    > particularly a servlet ? Thanks


    The best I can find is:

    RuntimeMXBean rtmb = ManagementFactory.getRuntimeMXBean();
    for(String s : rtmb.getInputArguments()) {
    System.out.println(s);
    }

    Arne
    Arne Vajhøj, Mar 22, 2009
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lucas Cowald
    Replies:
    4
    Views:
    1,035
    Tohid
    Oct 23, 2003
  2. Bernd Oninger
    Replies:
    1
    Views:
    776
    Martin Honnen
    Jul 7, 2004
  3. Replies:
    4
    Views:
    1,696
    Terry Hancock
    Apr 23, 2005
  4. Lucas Cowald

    RUN/execute a Command-Line command from an ASP page

    Lucas Cowald, Oct 22, 2003, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    224
    Genich
    Oct 22, 2003
  5. Lucas Cowald

    RUN/execute a Command-Line command from an ASP page.

    Lucas Cowald, Oct 22, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    191
    Oliver
    Oct 22, 2003
Loading...

Share This Page