JEP 293: Guidelines for JDK Command-Line Tool Options
|Discussion||core dash libs dash dev at openjdk dot java dot net|
|Reviewed by||Alan Bateman, Alex Buckley, Chris Hegarty, Mandy Chung, Mark Reinhold|
This informational JEP lays out guidelines for handling options in JDK command-line tools, including the Java launcher.
The JDK command-line tools have evolved over the years to use a variety of different conventions for the options they provide. For example:
- various tools:
- jar, in JDK 8:
Even the options used to show command-line help vary between different JDK tools,
--help being amongst the alternatives.
When new options are added to existing tools, and when new tools are added to the platform, it is desirable that options are used in a consistent manner.
In addition, it is becoming increasingly common for the command-line tools used by developers to use the GNU-style syntax, also described in getopt(3), in which the name of an option is given by a short series of words separated with hyphens, or an equivalent single character short form.
It is time for JDK tools to start becoming more consistent both with each other and with common prevailing industry practice. This does not mean that we should change all the options supported by all our tools overnight, but we should set guidelines for the use of new options in new and existing tools.
The GNU-style syntax provides a way forward: it can coexist reasonably well with the existing options of existing JDK tools; it is familiar to many, and it has library support which can be used for new tools.
Existing tools will continue to support existing options, but may also support new-style aliases for those options. And for both pragmatic and compatibility reasons, the new style may never be adopted for some existing options in existing tools.
The rules for option names are as follows:
Options have a long name, which is a short series of words, beginning with '--' and separated by '-'. For example:
Options may have a short, single character form. For example,
Options can require an argument to be provided. For a long-form options, the argument may be separated from the option name by either white space or '='. For single character options, the argument may immediately follow the character or may be separated by white space. For example:
Options can allow an argument to be provided. If such an argument is present, then the syntax of the option is the same as if the option required the argument. For example:
Case is always significant, in both the long name or single character forms. For example,
--Example-Optionis not the same as
Long form names may not be abbreviated on the command line. For example,
--example-ois not the same as
The use of options for subcommands is not included in the rules.
Single character options may be grouped into a single token. For example, if
-bare single character options, they may be specified together on the command line as
Although some option-decoding libraries may support grouping the single character form of a group of options into a single word, it is not required that this should be supported when the options being used require arguments to be provided. For example, a single character option that takes an argument may conflict with the use of an existing JDK-style argument.
For some options, the argument may be a series of values. When the values are file system locations, such as for directories or files, the values should be separated by the platform-specific path separator character (
;on Windows systems,
:on other platforms.) Otherwise, the recommended separator is a comma.
The use of
-Xas a prefix to indicate "non-standard" options will be discontinued for new options, although command-line help may continue to draw a distinction between more commonly used options and those for advanced use.
Some forms on the command-line may be ambiguous; tools may try and be clever to disambiguate such cases. In general, tools are encouraged not to support combinations which might be ambiguous, and users are encouraged not to use forms which might be ambiguous. For example, tools which support the old short form option
-cpfor classpath may choose not to support both
-pas single-character forms for new options.
Existing options defined in existing tools will continue to be supported until phased out or replaced, on a case by case basis. In some cases, that may be never.
The HotSpot VM will accept, via the JNI Invocation API, a subset of these rules,
in which new options are specified using the long form name, and using
= as the
separator for any argument value. The HotSpot VM will not change the form of any
of the current set of
The use of the '=' form will also make it easier to pass options from a tool
other than the launcher to the underlying VM using
For example, you can use a single
J option, as in
instead of having to use two
-J options as before:
= form also makes it possible to use a common form for the set of
options which may be provided to the Java launcher, the Hotspot VM (via the JNI interface)
and tools like
jdk.internal.opt module contains a copy of the JOptSimple library
for use by JDK modules which provide command-line tools.
Any tool that supports the ability to configure some aspect of the module system should provide an option that is consistent with other tools supporting equivalent functionality as much as possible. As a baseline, all tools and API should support the long form option, using '=' to separate an argument.
The set of common options is as follows. Note: the list is intended to just indicate the name of the options and the general form of any arguments it may take. The exact details of these options are specified elsewhere, such as JEP 261, or the documentation for the individual tool providing the option.
Not all tools may support all of these options. Some tools may not be able to support the single-character form, if it conflicts with a previously defined option.
Specifies the application module path.
Specifies the module path for upgradeable modules.
Specifies root modules to resolve in addition to the initial module.
Limits the universe of observable modules.
Add a read edge from
Add a qualified export of
Override or augment a module with classes and resources in JAR files or directories.
In addition, tools currently supporting a
-classpath option should support the
new-style long form option as equivalent:
Given the existing support for
-cp as a short form for
-classpath, a single
character form will not be introduced.
All tools should provide some amount of command-line help. At a minimum, the following should be supported.
In time, additional options that are common across different tools may be added to this list.
Users sometimes run into system limitations on the length of a command line when creating a command line with lots of options or with long arguments for options for a specific tool.
Tools for which this is a common problem may choose to support "argument files" or "@-files", containing strings to be expanded in place of the @file argument. Tools are encouraged to support the same syntax for the tokens within such an argument file.
Tools should support command-line help with a
Some options take complex structured values. The command-line help should use
the following rules to display such structured values:
Display the names of place-holders using
Use parentheses for grouping:
*for repetition, zero or more times.
Tools should ensure that the output for command line help fits within the width of a terminal using default terminal settings: this is typically 80 characters.
Tools that show command-line help for a long-form option that takes an argument
should normally show the option using a space to separate the argument, and provide
a note at the end that
= may also be used as a separator.
Tools providing equivalent options should provide the same command-line help text.