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

Add a new subsection for `TOOLING` script in the JShell Guide

XMLWordPrintable

    • Icon: Sub-task Sub-task
    • Resolution: Delivered
    • Icon: P4 P4
    • 21.0.3
    • None
    • docs
    • None

        Add a new subsection for `TOOLING` script

        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
              rgallard Raymond Gallardo
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: