Difference between _JAVA_OPTIONS, JAVA_TOOL_OPTIONS and JAVA_OPTS
You have pretty much nailed it except that these options are picked up even if you start JVM in-process via a library call.
The fact that _JAVA_OPTIONS
is not documented suggests that it is not recommended to use this variable, and I've actually seen people abuse it by setting it in their ~/.bashrc
. However, if you want to get to the bottom of this problem, you can check the source of Oracle HotSpot VM (e.g. in OpenJDK7).
You should also remember that there is no guarantee other VMs have or will continue to have support for undocumented variables.
UPDATE 2015-08-04: To save five minutes for folks coming from search engines, _JAVA_OPTIONS
trumps command-line arguments, which in turn trump JAVA_TOOL_OPTIONS
.
Difference between JAVA_OPTS and JAVA_TOOL_OPTIONS?
see "what is" doc and "tool options" doc
Basically, the JAVA_TOOL_OPTIONS
is intended for use by development tools, monitoring tools and the like whereas JAVA_OPTS
is used for running 'general' Java programs, I think people tend to mix and match somewhat (from what Google has shown me example wise).
What is the difference between JDK_JAVA_OPTIONS and JAVA_TOOL_OPTIONS when using Java 11?
The functional difference between the two variables is explained by @gjoranv's answer.
The differences in the output I think stem from the following:
The two variables seem to be implemented in different points in the launching process.
The
JDK_JAVA_OPTIONS
documentation says:In order to mitigate potential misuse of JDK_JAVA_OPTIONS behavior, options that specify the main class (such as -jar) or cause the java launcher to exit without executing the main class (such as -h) are disallowed in the environment variable. If any of these options appear in the environment variable, the launcher will abort with an error message.
This line:
Error: Cannot specify main class in environment variable JDK_JAVA_OPTIONS
is the error message that warns the user of a potential attempt to do mayhem via that variable.
I think that
JDK_JAVA_OPTIONS
takes precedence, in part for the same reason.
How do I use the JAVA_OPTS environment variable?
JAVA_OPTS
is the standard environment variable that some servers and other java apps append to the call that executes the java
command.
For example in tomcat if you define JAVA_OPTS='-Xmx1024m'
, the startup script will execute java org.apache.tomcat.Servert -Xmx1024m
If you are running in Linux/OSX, you can set the JAVA_OPTS, right before you call the startup script by doing
JAVA_OPTS='-Djava.awt.headless=true'
This will only last as long as the console is open.
To make it more permanent you can add it to your ~/.profile or ~/.bashrc file.
CATALINA_OPTS vs JAVA_OPTS - What is the difference?
There are two environment variables - CATALINA_OPTS
and JAVA_OPTS
- which are both used in the catalina.sh
startup and shutdown script for Tomcat.
CATALINA_OPTS: Comment inside catalina.sh:
# CATALINA_OPTS (Optional) Java runtime options used when the "start",
# "run" or "debug" command is executed.
# Include here and not in JAVA_OPTS all options, that should
# only be used by Tomcat itself, not by the stop process,
# the version command etc.
# Examples are heap size, GC logging, JMX ports etc.
JAVA_OPTS: Comment inside catalina.sh:
# JAVA_OPTS (Optional) Java runtime options used when any command
# is executed.
# Include here and not in CATALINA_OPTS all options, that
# should be used by Tomcat and also by the stop process,
# the version command etc.
# Most options should go into CATALINA_OPTS.
So why are there two different variables? And what's the difference?
Firstly, anything specified in EITHER variable is passed, identically, to the command that starts up Tomcat - the
start
orrun
command - but only values set inJAVA_OPTS
are passed to thestop
command. That probably doesn't make any difference to how Tomcat runs in practice as it only effects the END of a run, not the start.The second difference is more subtle. Other applications may also use
JAVA_OPTS
, but only Tomcat will useCATALINA_OPTS
. So if you're setting environment variables for use only by Tomcat, you'll be best advised to useCATALINA_OPTS
, whereas if you're setting environment variables to be used by other java applications as well, such as by JBoss, you should put your settings inJAVA_OPTS
.
Source: CATALINA_OPTS v JAVA_OPTS - What is the difference?
Related Topics
Delete Data from Arraylist with a For-Loop
How to Add Image in a Textview Text
Countdowntimer in Minutes and Seconds
How to Install Intellij Idea on Ubuntu
Getting Fonts, Sizes, Bold,...Etc
Get Domain Name from Given Url
Java Method to Swap Primitives
Java 8: Lambda-Streams, Filter by Method with Exception
Calculate Days Between Two Dates in Java 8
Java Map with Values Limited by Key's Type Parameter
Opengl Es2 Alpha Test Problems
Retrofit2 Android: Expected Begin_Array But Was Begin_Object at Line 1 Column 2 Path $
Installing Oracle Jdk on Windows Subsystem for Linux
Javax.Swing Timer Repeats Fine, But Actionlistener Doesn't Do Anything
Is There a Common Java Utility to Break a List into Batches