当前位置: 动力学知识库 > 问答 > 编程问答 >

tomcat - How to access jvmArgs from inside Java?

问题描述:

Suppose i have a configuration file like the following to start my application. How can i know from inside the application, value of, say, -Dlog4j.configuration

jvmArg=-server

jvmArg=-Xms512m

jvmArg=-Xmx1024m

jvmArg=-Dcatalina.base=tomcat

jvmArg=-Dcatalina.home={tomcat_HOME}

jvmArg=-Dcatalina.config=file:cfg/catalina.properties

jvmArg=-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager

jvmArg=-Djava.util.logging.config.file=cfg/logging.properties

javaMain=org.apache.catalina.startup.Bootstrap

javaMainArg=-config ../cfg/server.xml

javaMainArg=start

jvmArg=-Dlog.directory=log

jvmArg=-Dlog4j.configuration=file:/cfg/test/log4j.properties

网友答案:

Use System.getProperty() to get a map of all the variables. This only work for properties that start with -D.

To get all JVM arguments you can do

RuntimeMXBean runtimemxBean = ManagementFactory.getRuntimeMXBean();
List<String> arguments = runtimemxBean.getInputArguments();
网友答案:

-Dlog4j.configuration sets a system property, so for that: System.getProperty("log4j.configuration").

分享给朋友:
您可能感兴趣的文章:
随机阅读: