What is the difference between JDK_JAVA_OPTIONS and JAVA_TOOL_OPTIONS when using Java 11?

主宰稳场 提交于 2019-12-04 03:14:33

The functional difference between the two variables is explained by @gjoranv's answer.

The differences in the output I think stem from the following:

  1. The two variables seem to be implemented in different points in the launching process.

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

  • JDK_JAVA_OPTIONS is only picked up by the java launcher, so use it for options that you only want to apply (or only make sense for) the java startup command. This variable is also new on JDK 9+, and will be ignored by earlier JDK versions. Hence, it's useful when migrating from older versions to 9+.
  • JAVA_TOOL_OPTIONS is picked up also by other java tools like jar and javac so it should be used for flags that you want to apply (and are valid) to all those java tools.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!