RFR: 8340133: Add concise usage message to the java executable [v10]

Jan Lahoda jlahoda at openjdk.org
Fri Nov 29 07:25:23 UTC 2024


> Currently, running `java` without any parameters will lead to an output that is a full `--help`, which is over 100 lines (on my computer at least), and it feels overwhelming. And many people might actually want to run JShell/REPL, not the `java` executable, but it is difficult find out about JShell.
> 
> The proposal herein is to print a much shorter help, together with a pointer to JShell, when the executable does not know what to do. I.e. there is nothing specified to start, and no option like `--help` is specified. In particular, on my machine, it prints:
> 
> Usage: java [java options...] <application> [application arguments...]
> 
> Where <application> is one of:
>   <mainclass>                to execute the main method of a compiled main class
>   -jar <jarfile>.jar         to execute the main class of a JAR archive
>   -m <module>[/<mainclass>]  to execute the main class of a module
>   <sourcefile>.java          to compile and execute a source-file program
> 
> Where key java options include:
>   --class-path <class path>
>     where <class path> is a list of directories and JAR archives to search for class files, separated by ":"
>   --module-path <module path>
>     where <module path> is a list of directories and JAR archives to search for modules, separated by ":"
>   -version
>     to print product version to the error stream and exit
> 
> For additional help on usage:           java --help
> For an interactive Java environment:    jshell
> 
> 
> The full `java -help` with these changes is as follows:
> 
> Usage: java [options] <mainclass> [args...]
>            (to execute a class)
>    or  java [options] -jar <jarfile>.jar [args...]
>            (to execute a jar file)
>    or  java [options] -m <module>[/<mainclass>] [args...]
>        java [options] --module <module>[/<mainclass>] [args...]
>            (to execute the main class in a module)
>    or  java [options] <sourcefile>.java [args]
>            (to execute a source-file program)
> 
>  Arguments following the main class, source file, -jar <jarfile>.jar,
>  -m or --module <module>/<mainclass> are passed as the arguments to
>  main class.
> 
>  where options include:
> 
>     -cp <class search path of directories and zip/jar files>
>     -classpath <class search path of directories and zip/jar files>
>     --class-path <class search path of directories and zip/jar files>
>                   A ":"-separated list of directories, JAR archives,
>                   and ZIP archives to search for class files.
>     -p <module path>
>     --module-path <module path>...
>                ...

Jan Lahoda has updated the pull request incrementally with two additional commits since the last revision:

 - Dropping printing of the version.
 - Dropping the version from the concise help

-------------

Changes:
  - all: https://git.openjdk.org/jdk/pull/21411/files
  - new: https://git.openjdk.org/jdk/pull/21411/files/439fa40f..0d4eed05

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=21411&range=09
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=21411&range=08-09

  Stats: 23 lines in 5 files changed: 2 ins; 20 del; 1 mod
  Patch: https://git.openjdk.org/jdk/pull/21411.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/21411/head:pull/21411

PR: https://git.openjdk.org/jdk/pull/21411


More information about the core-libs-dev mailing list