Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8306560 Add TOOLING.jsh load file
  3. JDK-8314585

Update scripts chapter in JShell User's Guide

XMLWordPrintable

    • Icon: Sub-task Sub-task
    • Resolution: Delivered
    • Icon: P3 P3
    • 21
    • None
    • docs
    • None

      1. Extend table at top of https://docs.oracle.com/en/java/javase/20/jshell/scripts.htm Chapter 7 "Scripts" with a new row:

      TOOLING | Defines JShell methods accessing JDK Tools like `javac`, `javadoc`, and `javap` using their command-line interface.

      2. Add a new subsection for `TOOLING` script

      See JDK-8315230

      Since version 21 the JShell tool for interactive exploration of Java code has been enhanced with a new predefined script, `TOOLING`.

      The `TOOLING` script provides direct access to the JDK's command line tools, such as `javac`, `javadoc`, and `javap`, from within JShell. Similar to the existing predefined `DEFAULT` and `PRINTING` scripts, the `TOOLING` script can be loaded when JShell starts by running: `jshell TOOLING`. Alternatively, it can be loaded within a JShell session by using: `/open TOOLING`.

      With the `TOOLING` script loaded, observable tool services implementing the `java.util.spi.ToolProvider` interface can be run by passing a name and an array of arguments to the `run(String name, String... args)` method. Call `tools()` to print a sorted list of names for all runnable tools. For example:

      ```text
      jshell> tools()

      jar
      javac
      javadoc
      javap
      jdeps
      jlink
      jmod
      jpackage

      jshell> run("javac", "--version")
      ```

      For well-known JDK tools, the `TOOLING` script also defines convenient methods, such as `javac(String... args) { run("javac", args); }`, delegating to the `run` method. This shortens the last call of the previous example to:

      ```text
      jshell> javac("--version")
      ```

      In addition, the `javap` tool that disassembles class files is also represented by a `javap` method that takes a class literal. JShell users can have the `javap` tool disassemble and print an overview of a existing or newly created type without leaving the session:

      ```text
      jshell> javap(java.lang.Runnable.class)

      jshell> interface Empty {}
      jshell> javap(Empty.class)
      ```

            rgallard Raymond Gallardo
            cstein Christian Stein
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: