Details
-
Sub-task
-
Resolution: Delivered
-
P4
-
21
Description
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, JDK tools can be run by passing a name and arguments to the method `run(String name, String... args)`. The method `tools()` prints the names of available tools.
The `TOOLING` script defines convenience methods for the most commonly used tools, such as `javac(String... args)`. Here is an example of running the `javap` tool that disassembles and prints an overview of a class or interface:
```text
jshell> interface Empty {}
jshell> javap(Empty.class)
```
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, JDK tools can be run by passing a name and arguments to the method `run(String name, String... args)`. The method `tools()` prints the names of available tools.
The `TOOLING` script defines convenience methods for the most commonly used tools, such as `javac(String... args)`. Here is an example of running the `javap` tool that disassembles and prints an overview of a class or interface:
```text
jshell> interface Empty {}
jshell> javap(Empty.class)
```