3

My app is deployed on Tomcat and I've configured the JAVA_OPTS environment variable in /etc/default/tomcat7.

There seem to be a million different places where these variables can be provided to Tomcat, so I want to check that the values I'm providing are what's actually being used. Is there something I can inspect at runtime to determine the value of this variable. I checked System.getProperties(), but it doesn't seem to be there.

Dónal
  • 185,044
  • 174
  • 569
  • 824

3 Answers3

2

If you're looking for just the property overrides and JVM arguments, you can use RuntimeMXBean:

RuntimeMXBean mxBean = ManagementFactory.getRuntimeMXBean();
System.out.println(mxBean.getInputArguments());

For example, running with the following command-line:

java -Xms512m -Xmx1024m -Dtest.prop=foo com.example.sandbox.RuntimeMXBeanExample

I get the following output:

[-Xms512m, -Xmx1024m, -Dtest.prop=foo]

Note that this does not include arguments passed to the main() method.

parsifal
  • 296
  • 2
  • 4
2

You can use System.getenv("JAVA_OPTS") as suggested.

If you don't want to modify code than you can use some of those methods

Java Tools

  1. jps -v displays Java processes with arguments

  2. jvisualvm connects to Java process and let's you inspect number of properties including MXBeans

GNU/Linux tools

  1. ps e displays environment variables passed to processes
Grzegorz Żur
  • 47,257
  • 14
  • 109
  • 105
1

One important thing, although post is old. Whatever variable you are passing it should be before the class name you are executing else it will be ignored.

Below will work:

Example: java -classpath . -Dformat=xls -DTabname=\"Base data new\" com.cg.bench.GenerateReport

Below will NOT work:

WRONG Example: java -classpath . com.cg.bench.GenerateReport -Dformat=xls -DTabname=\"Base data new\"

shaILU
  • 2,050
  • 3
  • 21
  • 40