I tried looking around on the Internet for a way from code, to get the arguments passed to the JVM itself, rather than environment properties, system properties, and program arguments. As of Java 5, apparently it got a whole lot easy in code than before with the java.lang.management.ManagementFactory
.
Testing to see if you have a particular JVM argument is easy with a function like:
public boolean hasJvmArgument(String argument) { List arguments = ManagementFactory.getRuntimeMXBean().getInputArguments(); return arguments.contains(argument); }
Why would you want to do that?
For some systems, it’s critical the system operates under a specially configured environment. In our current system, for example, we have a health check that runs a series of tests to validate those assumptions still hold true. To achieve our performance targets, it’s integral our application starts with the correct JVM settings, and even with automation in place, we potentially have mistakes. Fortunately with the code above, we can simply add a JvmHasCorrectSettingsCheck to guarantee the application never gets deployed under the wrong circumstances.
Thanks to Saager Mhatre for pointing me in the right direction!