java 如何通过shell脚本执行java文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5497735/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to execute a java file by shell script
提问by BOSS
How to execute a java file by shell script?
如何通过shell脚本执行java文件?
采纳答案by das_weezul
If it's packed up as a jar:
如果它被打包成一个罐子:
java -jar jarfile.jar
回答by ZeWaren
If it is a class file:
如果是类文件:
java myClassFile
If it is a jar file:
如果是jar文件:
java -jar myJarFile.jar
See:
看:
回答by adarshr
java com.foo.Boo
java com.foo.Boo
回答by user11418600
All the answers only show the terminal commands to compile and run .java files but not the shell script to do so.
所有答案仅显示用于编译和运行 .java 文件的终端命令,而不显示用于执行此操作的 shell 脚本。
Below is the shell script. Let's call it compileRunJava.sh
下面是shell脚本。我们称之为 compileRunJava.sh
javac
java ${1%.java}
You may need to giv terminal the permission to run your script -
您可能需要授予终端运行脚本的权限 -
$ sudo chmod 754 compileRunJava.sh
Let's say your .java file is Hello.java. To run the script, cd to the directory where you have Hello.java. Run the below command -
假设您的 .java 文件是 Hello.java。要运行该脚本,请 cd 到您拥有 Hello.java 的目录。运行以下命令 -
$ /path/to/shell/script/directory/compileRunJava.sh Hello.java