Pass a Parameter to All JVMs in A Machine at The Same Time
In this tutorial we are going to see a scenario where you need to change a JVM parameter, but you can’t or is not a good solution to changing the start script of your server(s).
Imagine a scenario where you need to change a JVM parameter, but you can’t or is not a good solution to changing the start script of your server(s).
One of the challenges we had, when we were working with containers, was a way to change a parameter to a JVM without building the docker image again.
The application at the start time should read a JVM parameter where a user profilewas defined. For specific reasons we sometimes need to change this profile, for instance, to use a more controlled user where we can debug an issue. In these situations, we want to stop the container/pod, change the profile and start again, or even start a different container with a different profile.
As you know, the way to pass a JVM parameter to an application is
java -Dprofile=myValue com.some.Application appParameter1 appPaparameter2
What if I don’t have access, or is not viable to rewrite the above line?
You can add to the Environment variables of your operating system
Yes, you can add multiple values, since it is not a parameter, but an environment variable whose values will be injected into the JVM at starting time.
|“ When the JVM starts it search’s for this environment variable, and uses it. You can check the output of the JVM displaying a message with the values found.”|
This environment variable has a different purpose, it adds its values as a prefix to the Java other values
export JDK_JAVA_OPTIONS=‘-Dparam=value @someFile
When we execute this:
The real execution is:
java -Dparam=value @somefile @otherFile