How to execute a java file by shell script?
If it's packed up as a jar:
java -jar jarfile.jar
If it is a class file:
java myClassFile
If it is a jar file:
java -jar myJarFile.jar
See:
java com.foo.Boo
All the answers only show the terminal commands to compile and run .java files but not the shell script to do so.
Below is the shell script. Let's call it compileRunJava.sh
javac $1
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 -
$ /path/to/shell/script/directory/compileRunJava.sh Hello.java
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With