开发者

is it possible to log how the jvm was called (including all -D -Xmx etc)

开发者 https://www.devze.com 2023-02-27 00:47 出处:网络
In order to facilitate troubleshooting, I would like to log to our log files exactly how the java process was invoked.

In order to facilitate troubleshooting, I would like to log to our log files exactly how the java process was invoked.

This should ideally include:

  • arguments: ok that is easy, I开发者_Python百科 am already doing that.
  • -Xmx256m -XX:+UseParallelGC type stuff
  • -Dsome.arg=VALUE stuff
  • other params like -server -cp "./lib;./bin" ...

Is there a way to do this?

EDIT: I NEED to do this from inside java, not outside


Use RuntimeMXBean.getInputArguments():

List<String> arguments = ManagementFactory.getRuntimeMXBean().getInputArguments();

This will only return arguments that are passed to the JVM during initialization.

Further information might be found with the other methods of RuntimeMXBean, such as getClassPath(), getVmName(), ...


You have a batch file which starts your application and have the echo statements to print the details you listed above.

For example have a ENV VAR as JAVA_OPTS then set the value for it as below

set JAVA_OPTS=%JAVA_OPTS% -Xms512m -Xmx1024m -XX:MaxPermSize=256m -Xms128m -Xmx1024m

Once it is set use the echo statements like below to print the details.

echo   JAVA_OPTS: %JAVA_OPTS%
0

精彩评论

暂无评论...
验证码 换一张
取 消