RFR: 8340133: Investigate if the java launcher could give hints about JShell [v2]

Jan Lahoda jlahoda at openjdk.org
Thu Oct 10 17:59:12 UTC 2024


On Thu, 10 Oct 2024 17:54:51 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

>> 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` launcher, 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 launcher 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:
>> 
>> $ java
>> openjdk 24-internal 2025-03-18
>> 
>> Usage: java [options...] <what to execute> [arguments to main method...]
>> 
>> Where <what to execute> is one of:
>>   <MainClass>                to execute the main method of a compiled class
>>   -jar <jar-file.jar>        to execute the main class in a JAR archive
>>   -m <module>[/<MainClass>]  to execute the main class of a module
>>   <SourceFile.java>          to compile and execute a single-file program
>> 
>> Where key options include:
>>   --class-path <class path>
>>       a : separated list of directories and JAR archives to search for class files
>>   --module-path <module path>
>>       a : separated list of directories and JAR archives to search for modules
>> 
>> For more details about this launcher:   java --help
>> For an interactive Java environment:    jshell
>> 
>> 
>> Hopefully, this may be easier both for people trying to run something, and for people that are really looking for JShell.
>> 
>> What do you think?
>> 
>> Thanks!
>
> Jan Lahoda has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Adjusting the concise help based on review suggestions.

I've adjusted the concise help to:

$ java
openjdk 24-internal 2025-03-18

Usage: java [java options...] <application> [application arguments...]

Where <application> is one of:
  <MainClass>                to execute the main method of a compiled class
  -jar <jar-file.jar>        to execute the main class in a JAR archive
  -m <module>[/<MainClass>]  to execute the main class of a module
  <SourceFile.java>          to compile and execute a single-file program

Where key java options include:
  --class-path <class path>
      a ":"-separated list of directories and JAR archives to search for class files
  --module-path <module path>
      a ":"-separated list of directories and JAR archives to search for modules

For more details about this launcher:   java --help
For an interactive Java environment:    jshell


@magicus' suggestion with `<application>` seemed good, so I used that. Regarding the `: separated list` problem, chose `":"-separated list`, as that is still reasonably easy to do.

Regarding "launcher" - sorry, but I don't think this is meant to refer to launcher architecture or to multiple launchers. `java` is a launcher for Java programs, and (to me, at least) "For more details about this launcher:   java --help" does not seem to require any very special knowledge - it is simply about listing the options for this specific launcher.

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

PR Comment: https://git.openjdk.org/jdk/pull/21411#issuecomment-2405723643


More information about the core-libs-dev mailing list