Reputation: 187499
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.
Upvotes: 3
Views: 14111
Reputation: 2116
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\"
Upvotes: 1
Reputation: 49161
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
jps -v
displays Java processes with arguments
jvisualvm
connects to Java process and let's you inspect number of properties including MXBeans
GNU/Linux tools
ps e
displays environment variables passed to processesUpvotes: 2
Reputation: 296
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.
Upvotes: 2