如何运行JShell文件? [英] How to run a JShell File?
本文介绍了如何运行JShell文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用JShell运行整个文件,例如:
I'd like to run an entire file with JShell like:
$ jshell my-jshell-skript.java
例如我的my-jshell-skript.java
的内容是40 + 2;
.
或可执行文件,例如:
#!/usr/bin/jshell
40 + 2
现在有可能吗?还是我仍然需要沿用Java-Main-Class的旧方法?
Is this possible now or do I still have to take the old way over a Java-Main-Class?
在Windows上,仍然没有适合我的解决方案:
On Windows, there is still no solution for me:
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>
JShell开始完全忽略我的文件.是虫子吗?
JShell starts ignoring my file completely. Is it a bug?
原来,这是我的foo的内容.似乎1 + 1
只能即时"运行,而不能从文件中读取:
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:\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>
推荐答案
JShell
并不意味着直接运行Java类.如果要运行Java类,则仍然需要使用旧方法-java <your-class-name>
.
JShell
is not meant to run a Java class directly. If you want to run a java class, you still need to do it the old way - java <your-class-name>
.
查看全文