Getting the parameters passed to the VM at runtime

With the new java.lang.management package in JDK 1.5, this becomes very simple now.

Main.java:

import java.lang.management.*;
import java.util.*;
 
public class Main
{
   public static void main(String []args) {
      RuntimeMBean mbean = ManagementFactory.getRuntimeMBean();
      List list = mbean.getInputArguments();
       
      Iterator iter = list.iterator();
      while (iter.hasNext()) {
         String s = (String) iter.next();
         System.out.println(s);
      }
   }
}

For example, run it with

java -Xmx200M -Xrs Main

outputs:

-Xmx200M
-Xrs