问题
I want to compile and run in the single command line. Usually, we first compile and after the run?
javac example.java
java example
can I run this,
javac example.java && java example
回答1:
You can use a function :
Myfunction() { javac $1.java && java $1 ; }
The use :
Myfunction example
This question is duplicated , please to search before posting See : Compile and build with single command line Java (Linux)
Regards
回答2:
Since Java 11 you can use a single command
java example.java
https://openjdk.java.net/jeps/330
来源:https://stackoverflow.com/questions/57180304/how-to-compile-and-run-in-single-command-in-java