<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <p>1. You can only use the `-J` option for tools like `javac` when
      invoking the tool through the "wrapper" in `bin/javac` (or
      `bin/javac.exe` on Windows.  `-J` is used to pass options to the
      VM used to run the tool, and is not supported when running `javac`
      through an API entry point in an already-running JVM.  This is
      because it is then "too late" to pass any options to that JVM.</p>
    <p>2. If you use `-J` in conjunction with `--add-exports` or `-D`
      you are only affecting the JVM used to run `javac` and not the
      compilation environment used to compile your program. As such,
      generally, the only reason to do so is to affect the environment
      used to execute any annotation processors you may be using (if
      any).  In other words, use `-J-add-exports` if you want to affect
      the runtime environment used by `javac` to run annotation
      processors; use plain `--add-exports` if you want to affect the
      compilation environment used to compile your program.</p>
    <p>If you are seeing a change in the behavior in the response to
      using `-J`, you should look to changes in how your system is
      invoking `javac`.</p>
    <p>-- Jon<br>
    </p>
    <div class="moz-cite-prefix">On 8/7/24 8:35 AM, Dimitri John Ledkov
      wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:CANBHLUhj9_C8UJ+1Zju=SkfuvvixB9zjXmK_cQWSzxR0W1G7MQ@mail.gmail.com">
      
      <div dir="ltr">Hi,
        <div><br>
        </div>
        <div>I've searched all forums, stackoverflow, release notes,
          documentation and attempted to read openjdk source code. I am
          not sure if below environment variables options are supposed
          to work, if they do anything, and how they should be done. The
          behaviour change is in JDK 18, but in practice I only care
          about how it should be done in JDK 11, 17, 21.</div>
        <div><br>
        </div>
        <div>With java 17</div>
        <div><br>
        </div>
        <div>$ docker run -ti \</div>
        <div>--env
'JDK_JAVAC_OPTIONS="-J--add-exports=java.base/sun.security.internal.spec=ALL-UNNAMED"'
          \</div>
        <div>--entrypoint javac openjdk:17 --version</div>
        <div>javac 17.0.2<br clear="all">
          <div><br>
          </div>
          <div>$ docker run -ti \</div>
          <div>--env
            'JDK_JAVAC_OPTIONS="-J-Djavax.net.ssl.trustStoreType=PKCS12"'
            \</div>
          <div>--entrypoint javac openjdk:17 --version<br>
            javac 17.0.2<br>
          </div>
          <div><br>
          </div>
          <div>And yet with java 18 (19, 20, 21, 22)</div>
          <div><br>
          </div>
          <div>
            <div>
              <div>$ docker run -ti \</div>
              <div>--env
'JDK_JAVAC_OPTIONS="-J--add-exports=java.base/sun.security.internal.spec=ALL-UNNAMED"'
                \</div>
              <div>--entrypoint javac openjdk:18 --version</div>
            </div>
            <div>jerror: invalid flag:
              -J--add-exports=java.base/sun.security.internal.spec=ALL-UNNAMED<br>
              Usage: javac <options> <source files><br>
              use --help for a list of possible options<br clear="all">
              <div><br>
              </div>
              <div>$ docker run -ti \</div>
              <div>--env
                'JDK_JAVAC_OPTIONS="-J-Djavax.net.ssl.trustStoreType=PKCS12"'
                \</div>
              <div>--entrypoint javac openjdk:18 --version<br>
                error: invalid flag:
                -J-Djavax.net.ssl.trustStoreType=PKCS12<br>
                Usage: javac <options> <source files><br>
                use --help for a list of possible options<br>
              </div>
              <div><br>
              </div>
            </div>
          </div>
          <div>Can anybody point me at relevant documentation or source
            code changes?</div>
          <div>Or otherwise explain how to pass these options correctly?</div>
          <div>Should they even be set in JDK_JAVAC_OPTIONS?</div>
          <div>Should  one specify '--add-exports' without '-J' prefix?</div>
          <div>How does one specify trustStoreType - or does '-J-D' flag
            doesn't actually do anything in JDK_JAVAC_OPTIONS?</div>
          <div><br>
          </div>
          <div>Ideally looking for environment variables to set in my
            Dockerfile, rather than command line arguments.</div>
          <div><br>
          </div>
          <span class="gmail_signature_prefix">-- </span><br>
          <div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">Regards,<br>
            <br>
            Dimitri.</div>
        </div>
      </div>
    </blockquote>
  </body>
</html>