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
is 40 + 2;
.
Or alternatively an executable like:
#!/usr/bin/jshell
40 + 2
Is this possible now or do I still have to take the old way over a Java-Main-Class?
Edit 1: Windows-Problem
On Windows, there is still no solution for me:
C:JDKsjdk9.0.0.0_x64in>type foo.jsh
1 + 1
C:JDKsjdk9.0.0.0_x64in>jshell.exe foo.jsh
| Welcome to JShell -- Version 9
| For an introduction type: /help intro
jshell> /exit
| Goodbye
C:JDKsjdk9.0.0.0_x64in>
JShell starts ignoring my file completely. Is it a bug?
Edit 2: Solution for Windows-Problem
Turns out that it is the content of my foo. Seems like 1 + 1
does only work "on the fly", not read from a file:
C:JDKsjdk9.0.0.0_x64in>type foo.jsh
System.out.println("foo");
C:JDKsjdk9.0.0.0_x64in>jshell.exe foo.jsh
foo
| Welcome to JShell -- Version 9
| For an introduction type: /help intro
jshell> /exit
| Goodbye
C:JDKsjdk9.0.0.0_x64in>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…