Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8327491 | 22 | Raymond Gallardo | P4 | Closed | Delivered |
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)
```
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)
```
- backported by
-
JDK-8327491 Add a new subsection for `TOOLING` script in the JShell Guide
- Closed