29

When should each of these environment variables be used?

Daniel Perez Alvarez
  • 6,570
  • 5
  • 28
  • 27
  • Possible duplicate of [Difference between \_JAVA\_OPTIONS JAVA\_TOOL\_OPTIONS and JAVA\_OPTS](http://stackoverflow.com/questions/28327620/difference-between-java-options-java-tool-options-and-java-opts) – Vadzim Oct 27 '15 at 20:27

2 Answers2

18

JAVA_TOOL_OPTIONS is read by some JDK tools, but has limited applicability.

JAVA_OPTS is a convention used by Apache Tomcat and some other apps, but is not read directly by any JDK tools published by Sun/Oracle, AFAIK.

From: https://forums.oracle.com/forums/thread.jspa?messageID=6438415

JAVA_OPTS is not an environment variable that the java executable will recognize on it's own. Instead, various scripts which wrap the start up of java will often use an environment variable named JAVA_OPTS to configure the java executable (for example, the tomcat startup script does this).

Mysticial
  • 464,885
  • 45
  • 335
  • 332
Stu Btwotwo
  • 189
  • 1
  • 3
17

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).

David Ferenczy Rogožan
  • 23,966
  • 9
  • 79
  • 68
Martijn Verburg
  • 3,287
  • 21
  • 26
  • One real-world example: JAVA_TOOL_OPTIONS is used by TeamCity CI to pass settings to step runners such as "Simple Build Tool" (Scala SBT), and users need use JAVA_OPTS in order to not clobber the implicit system parameters passed on by the TeamCity server such as - http_proxy could be one of these. – conny Aug 16 '21 at 11:17
  • Another difference is that when JAVA_TOOL_OPTIONS is defined, a message is always echoed to stdout, like `Picked up JAVA_TOOL_OPTIONS: -XX:+UseG1GC -Xmx4G`. – conny Aug 16 '21 at 11:28
  • If it's of value for readers using later JVMs, those links above can be found also for [java 17](https://docs.oracle.com/en/java/javase/17/docs/specs/jvmti.html#tooloptions) or [java 11](https://docs.oracle.com/en/java/javase/11/docs/specs/jvmti.html#tooloptions). – charlie arehart Feb 11 '22 at 21:04