title: What is the difference between JDK_JAVA_OPTIONS and JAVA_TOOL_OPTIONS when using Java 11?
body: <p>What is the exact difference between <a href="https://docs.oracle.com/en/java/javase/11/tools/java.html#GUID-3B1CE181-CD30-4178-9602-230B800D4FAE__USINGTHEJDK_JAVA_OPTIONSLAUNCHERENV-F3C0E3BA" rel="noreferrer">JDK_JAVA_OPTIONS</a> and <a href="https://docs.oracle.com/en/java/javase/11/troubleshoot/environment-variables-and-system-properties.html#GUID-BE6E7B7F-A4BE-45C0-9078-AA8A66754B97" rel="noreferrer">JAVA_TOOL_OPTIONS</a> when using Java 11?</p>
  <p>I'm using a tiny test program:</p>
  <pre><code>public class Foo {
    public static final void main(String[] args) {
      System.out.println(&quot;arg: &quot; + System.getProperty(&quot;arg&quot;));
    }
  }
  </code></pre>
  <p>The two environment variables seem to do the same, but the output is slightly different.  That makes me believe they might have different use cases:</p>
  <pre><code>$ JDK_JAVA_OPTIONS=&quot;-Darg=jdk&quot; java Foo
  NOTE: Picked up JDK_JAVA_OPTIONS: -Darg
  arg: jdk
  
  $ JAVA_TOOL_OPTIONS=&quot;-Darg=tool&quot; java Foo
  Picked up JAVA_TOOL_OPTIONS: -Darg
  arg: tool
  
  $ JDK_JAVA_OPTIONS=&quot;illegalArg&quot; java Foo
  NOTE: Picked up JDK_JAVA_OPTIONS: illegalArg
  Error: Cannot specify main class in environment variable JDK_JAVA_OPTIONS
  
  $ JAVA_TOOL_OPTIONS=&quot;illegalArg&quot; java Foo
  Picked up JAVA_TOOL_OPTIONS: illegalArg
  Unrecognized option: illegalArg
  Error: Could not create the Java Virtual Machine.
  Error: A fatal exception has occurred. Program will exit.
  </code></pre>
  <p>It seems like <code>JDK_JAVA_OPTIONS</code> have precedence over <code>JAVA_TOOL_OPTIONS</code>:</p>
  <pre><code>$ JDK_JAVA_OPTIONS=&quot;-Darg=jdk&quot; JAVA_TOOL_OPTIONS=&quot;-Darg=tool&quot; java Foo
  NOTE: Picked up JDK_JAVA_OPTIONS: -Darg=jdk
  Picked up JAVA_TOOL_OPTIONS: -Darg=tool
  arg: jdk
  </code></pre>
  <p>But ultimately the command line wins:</p>
  <pre><code>$ JDK_JAVA_OPTIONS=&quot;-Darg=jdk&quot; JAVA_TOOL_OPTIONS=&quot;-Darg=tool&quot; java -Darg=cmd Foo
  NOTE: Picked up JDK_JAVA_OPTIONS: -Darg=jdk
  Picked up JAVA_TOOL_OPTIONS: -Darg=tool
  arg: cmd
  </code></pre>
  <p>When building, though, only <code>JAVA_TOOL_OPTIONS</code> is read:</p>
  <pre><code>$ JDK_JAVA_OPTIONS=&quot;-Darg=jdk&quot; JAVA_TOOL_OPTIONS=&quot;-Darg=tool&quot; javac Foo.java
  Picked up JAVA_TOOL_OPTIONS: -Darg=tool
  </code></pre>
  <p>I'm currently using AdoptOpenJDK 11 build 28.</p>