What is the difference between JDK_JAVA_OPTIONS and JAVA_TOOL_OPTIONS when using Java 11?(使用 Java 11 时 JDK_JAVA_OPTIONS 和 JAVA_TOOL_OPTIONS 有什么区别?)
问题描述
JDK_JAVA_OPTIONS 和 JAVA_TOOL_OPTIONS 使用 Java 11 时?
What is the exact difference between JDK_JAVA_OPTIONS and JAVA_TOOL_OPTIONS when using Java 11?
我正在使用一个小型测试程序:
I'm using a tiny test program:
这两个环境变量似乎做的一样,但输出略有不同.这让我相信他们可能有不同的用例:
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:
似乎 JDK_JAVA_OPTIONS
优先于 JAVA_TOOL_OPTIONS
:
但最终还是命令行获胜:
But ultimately the command line wins:
但是,在构建时,只读取 JAVA_TOOL_OPTIONS
:
When building, though, only JAVA_TOOL_OPTIONS
is read:
我目前正在使用 AdoptOpenJDK 11 build 28.
I'm currently using AdoptOpenJDK 11 build 28.
推荐答案
@gjoranv 的回答解释了两个变量之间的功能差异.
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.
JDK_JAVA_OPTIONS
文档说:
为了减少对 JDK_JAVA_OPTIONS 行为的潜在滥用,环境变量中不允许指定主类(例如 -jar)或导致 java 启动器退出而不执行主类的选项(例如 -h).如果这些选项中的任何一个出现在环境变量中,启动器将中止并显示错误消息.
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.
这一行:
是警告用户可能尝试通过该变量进行破坏的错误消息.
is the error message that warns the user of a potential attempt to do mayhem via that variable.
我认为 JDK_JAVA_OPTIONS
优先,部分原因是相同的.
I think that JDK_JAVA_OPTIONS
takes precedence, in part for the same reason.
这篇关于使用 Java 11 时 JDK_JAVA_OPTIONS 和 JAVA_TOOL_OPTIONS 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!