I\'d like to run an entire file with JShell like:
$ jshell my-jshell-skript.java
Where e.g. the content of my my-jshell-skript.java>
In jshell you can save the current snippets into a file by issuing:
/save Filename
Likewise, you can load the file into the current context/session by issuing:
/open Filename
Here is one such example:
| Welcome to JShell -- Version 9.0.7.1
| For an introduction type: /help intro
jshell> String[] names={"nameone","nametwo"}
names ==> String[2] { "nameone", "nametwo" }
jshell> Arrays.toString(names);
$2 ==> "[nameone, nametwo]"
jshell> /save myExample
jshell> % sudipbhandari at sysadm-Latitude-5480 in ~ 18:22
> jshell
| Welcome to JShell -- Version 9.0.7.1
| For an introduction type: /help intro
jshell> names
| Error:
| cannot find symbol
| symbol: variable names
| names
| ^---^
jshell> /open myExample
jshell> names
names ==> String[2] { "nameone", "nametwo" }