我想用JShell运行整个文件,如:
$ jshell my-jshell-skript.java
Run Code Online (Sandbox Code Playgroud)
例如,在哪里我的内容my-jshell-skript.java是40 + 2;.
或者可选的可执行文件:
#!/usr/bin/jshell
40 + 2
Run Code Online (Sandbox Code Playgroud)
现在这可能吗?还是我仍然需要采用Java-Main-Class的旧方法?
在Windows上,我仍然没有解决方案:
C:\JDKs\jdk9.0.0.0_x64\bin>type foo.jsh
1 + 1
C:\JDKs\jdk9.0.0.0_x64\bin>jshell.exe foo.jsh
| Welcome to JShell -- Version 9
| For an introduction type: /help intro
jshell> /exit
| Goodbye
C:\JDKs\jdk9.0.0.0_x64\bin>
Run Code Online (Sandbox Code Playgroud)
JShell开始完全忽略我的文件.这是一个错误吗?
事实证明这是我的foo的内容.似乎1 + 1只能"在运行中"工作,而不是从文件中读取:
C:\JDKs\jdk9.0.0.0_x64\bin>type foo.jsh
System.out.println("foo");
C:\JDKs\jdk9.0.0.0_x64\bin>jshell.exe foo.jsh
foo
| Welcome to JShell -- Version 9
| For an introduction type: /help intro
jshell> /exit
| Goodbye
C:\JDKs\jdk9.0.0.0_x64\bin>
Run Code Online (Sandbox Code Playgroud)