Reputation: 7543
How can I get all the CATALINA_OPTS
and/or JAVA_OPTS
parameters in a Java web app?
I know I can read System.getProperties()
to get all the system properties. However, it will just show all system properties, including the -D
parameters passed via CATALINA_OPTS
. Not any parameters like -Xmx
, -Xms
, etc.
I know I can read ManagementFactory.getRuntimeMXBean()
to get all the Java parameters. However, this also shows just the -D
parameters. Not any parameters like -Xmx
, -Xms
, etc.
Upvotes: 1
Views: 2286
Reputation: 111
Environment variables can usually be accessed through System.getenv():
String javaOpts = System.getenv("JAVA_OPTS"); // gets one value
Map<String, String> all = System.getenv(); // gets all the environment strings
Upvotes: 5
Reputation: 201399
If I understand your question, you can use System.getenv(String)
like so
String catalinaOpts = System.getenv("CATALINA_OPTS");
String javaOpts = System.getenv("JAVA_OPTS");
System.out.printf("JAVA_OPTS = %s CATALINA_OPTS = %s%n", javaOpts, catalinaOpts);
Upvotes: 3