开发者

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.properti开发者_如何学Goes
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").

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜