Is it possible to get the command used to launch the jvm in java?

前端 未结 5 970
长情又很酷
长情又很酷 2020-12-09 01:15

I would like to know if it is possible to get from code the command used to launch a java program.

E.g. if I launch a java program with:

 java -cp li         


        
5条回答
  •  离开以前
    2020-12-09 01:53

    You can use this to retrieve the VM parameters :

    public static void main(String args[]) {
        List inputArguments = ManagementFactory.getRuntimeMXBean().getInputArguments();
        System.out.println("input arguments = " + inputArguments);
    }
    

    However it won't give you all the command line (only gives the JVM arguments, no main class nor parameters). Sample output:

    input arguments = [-Dfile.encoding=UTF-8, -XX:-UseTLAB, -Xms2000m, -Xmx2000m, -XX:+PrintCompilation, -XX:+PrintGC]

提交回复
热议问题