JDK-8170832 : Add a new launcher environment variable JAVA_OPTIONS
  • Type: Enhancement
  • Component: tools
  • Sub-Component: launcher
  • Affected Version: 9
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2016-12-07
  • Updated: 2022-09-14
  • Resolved: 2017-01-26
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 10 JDK 9
10Fixed 9 b155Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Sub Tasks
JDK-8178072 :  
JDK-8185446 :  
`_JAVA_OPTIONS` and `JAVA_TOOL_OPTIONS` environment variable are interpreted by the VM, not the launcher, hence no @-files or launcher-only options.  The former is undocumented and unsupported but widely used; the latter is documented and supported.

In JDK 9, javac adds a new `_JAVAC_OPTIONS` environment variable whose name was chosen to match `_JAVA_OPTIONS` but their semantics are not consistent (e.g. prepend vs append).

There is no equivalent environment variable support in the `java` launcher.

This proposes to introduce a new launcher enviornment variable `JAVA_OPTIONS` that is read by the java launcher.  It will support multiple @files. Its content will be prepended to the actual command line; consistent with the current javac environment variable.   Other JDK command-line tools will follow this general pattern `<TOOL>_OPTIONS`, if a tool-specific environment variable is supported.

URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/d8dbac6098fe User: lana Date: 2017-02-01 21:14:30 +0000

Does the new JAVA_OPTIONS support spaces in arguments - as per the issue reported in JDK-8173128?

URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/d8dbac6098fe User: henryjen Date: 2017-01-26 23:04:43 +0000

FC Extension Request This enhancement provides a consistent environment variable support in java launcher and javac that tool-specific options specified in an environment variable `JAVA_OPTIONS` and `JAVAC_OPTIONS` will be prepended to the command-line of the java launcher and javac respectively. This will clear the potential confusion caused by inconsistencies among the existing mechanisms such as _JAVA_OPTIONS environment variable, launcher @file, VM -XX:VMOptionsFile option, _JAVAC_OPTIONS that have caused confusion to the users. This also defines the guideline for other JDK command-line tools when supporting tool-specific environment variable `<TOOL>_OPTIONS`. This enhancement is completed and can be pushed to jdk9 as soon as this request gets approved.

The following specified how JAVA_OPTIONS works: The content of the environment variable will be a list of arguments separated by white-space characters(as determined by isspace()) to be prepended to the command line arguments passed to `java` launcher. The encoding requirement for the environment variable is the same as java command line on the system, as the environment variable content is treated just like specified in the command line. Single(`'`) or double(`"`) quote can be used to enclose arguments which contain whitespace characters. All content between the open quote and the first matching close quote will be preserved by simply removing the pair of quotes. In case a matching quote is not found, the launcher will abort with an error message. @files are supported as they are specified in the command line. However, like in @files, wildcard is not supported in the environment variable. In order to mitigate potentially misuse of JAVA_OPTIONS interfering expected behavior, options that specify the main class(such as -jar) or cause java to exit without executing the main class(such as -h) are disallowed in the environment variable. If any of such options appears in the environment variable, the launcher will abort with an error message. Also, when JAVA_OPTIONS is set, the launcher will print a message to stderr as a reminder. To be clear, JAVA_OPTIONS will only apply to 'java', not other launcher-based tools such as javac. With this proposal, nothing changes for the processing of _JAVA_OPTIONS if JAVA_OPTIONS is also specified. Examples: export JAVA_OPTIONS='-g @file1 -Dprop=value @file2 -Dws.prop="white spaces”' $ java -Xint @file3 will be equivalent to a command line of: $ java -g @file1 -Dprop=value @file2 -Dws.prop="white spaces" -Xint @file3 Following examples helps to understand how quote works, export JAVA_OPTIONS=‘@"C:\white spaces\argfile”' export JAVA_OPTIONS=‘"@C:\white spaces\argfile”' export JAVA_OPTIONS='@C:\"white spaces"\argfile' All above have same effects to specify the "c:\white spaces\argile" as the argument file, as the matching pair of " are removed and there is only one argument specified. We also propose to change the option '-Xdisable-@files' to '--disable-@files' to adapt the new naming convention in JDK9. -Xdisable-@files is proposed in CCC 8027634, which is new in 9, thus rename to the new convention make sense and has no impact to compatibility.