I thought it would be great to have a comparison between _JAVA_OPTIONS
and JAVA_TOOL_OPTIONS
.
I have been searching a bit for one, but I cannot find anything, so I hope we can find the knowledge here on Stackoverflow.
JAVA_OPTS
is included for completeness. It is not part of the JVM, but there is a lot of questions about it out in the wild.
What I know:
So far I have found out that:
JAVA_OPTS
is not used by the JDK, but by a bunch of other apps (see this post).JAVA_TOOL_OPTIONS
and_JAVA_OPTIONS
are ways to specify JVM arguments as an environment variable instead of command line parameters.- The are picked up by at least
java
andjavac
- They have this precedence:
_JAVA_OPTIONS
(overwrites the others)- Command line parameters
JAVA_TOOL_OPTIONS
(is overwritten by the others)
- The are picked up by at least
What I would like to know
- Are there any official documentation comparing
JAVA_TOOL_OPTIONS
and_JAVA_OPTIONS
- Are there any other differences between
JAVA_TOOL_OPTIONS
and_JAVA_OPTIONS
(except from precedence). - Which executables pick up
JAVA_TOOL_OPTIONS
and_JAVA_OPTIONS
(in addition tojava
andjavac
) - Any limitation on what can be included on
JAVA_TOOL_OPTIONS
and_JAVA_OPTIONS
Official Documentation
I have not been able to find any documentation about _JAVA_OPTIONS
. The documentation for JAVA_TOOL_OPTIONS
does not shed much light on the difference:
Since the command-line cannot always be accessed or modified, for example in embedded VMs or simply VMs launched deep within scripts, a JAVA_TOOL_OPTIONS variable is provided so that agents may be launched in these cases.
...
Example script
This is the code I used to figure this out. Console output is included as comments:
export JAVA_OPTS=foobar
export JAVA_TOOL_OPTIONS=
export _JAVA_OPTIONS="-Xmx512m -Xms64m"
java -version
# Picked up JAVA_TOOL_OPTIONS:
# Picked up _JAVA_OPTIONS: -Xmx512m -Xms64m
# java version "1.7.0_40"
OpenJDK Runtime Environment (IcedTea 2.4.1) (suse-3.41.1-x86_64)
OpenJDK 64-Bit Server VM (build 24.0-b50, mixed mode)
javac -version
# Picked up JAVA_TOOL_OPTIONS:
# Picked up _JAVA_OPTIONS: -Xmx512m -Xms64m
# javac 1.7.0_40
export JAVA_TOOL_OPTIONS="-Xmx1 -Xms1"
export _JAVA_OPTIONS="-Xmx512m -Xms64m"
javac -version
# Picked up JAVA_TOOL_OPTIONS: -Xmx1 -Xms1
# Picked up _JAVA_OPTIONS: -Xmx512m -Xms64m
# javac 1.7.0_40
export JAVA_TOOL_OPTIONS="-Xmx512m -Xms64m"
export _JAVA_OPTIONS="-Xmx1 -Xms1"
javac -version
# Picked up JAVA_TOOL_OPTIONS: -Xmx512m -Xms64m
# Picked up _JAVA_OPTIONS: -Xmx1 -Xms1
# Error occurred during initialization of VM
# Too small initial heap
export JAVA_TOOL_OPTIONS="-Xmx1 -Xms1"
export _JAVA_OPTIONS=
java -Xmx512m -Xms64m -version
# Picked up JAVA_TOOL_OPTIONS: -Xmx1 -Xms1
# Picked up _JAVA_OPTIONS:
# java version "1.7.0_40"
# OpenJDK Runtime Environment (IcedTea 2.4.1) (suse-3.41.1-x86_64)
# OpenJDK 64-Bit Server VM (build 24.0-b50, mixed mode)
export JAVA_TOOL_OPTIONS=
export _JAVA_OPTIONS="-Xmx1 -Xms1"
java -Xmx512m -Xms64m -version
# Picked up JAVA_TOOL_OPTIONS:
# Picked up _JAVA_OPTIONS: -Xmx1 -Xms1
# Error occurred during initialization of VM
# Too small initial heap
JDK_JAVA_OPTIONS
as the preferred replacement, see https://mcmap.net/q/57224/-what-is-the-difference-between-jdk_java_options-and-java_tool_options-when-using-java-11/537554 – Heavyarmed