问题
Is there any way to execute "javac and java commands" from java program?
If so,please help me out....
回答1:
Like Runtime.getRuntime().exec("javac ...");
?
回答2:
You can use Runtime.getRuntime.exec()
to do this. But there're some common traps that you take care of. This article on "When Runtime.exec() won't" work correctly highlights some of them.
回答3:
You can use the ProcessBuilder class
ProcessBuilder pb =
new ProcessBuilder("javac", "arg1, "arg2");
回答4:
I would suggest using http://docs.oracle.com/javase/6/docs/technotes/tools/ instead of attempting to execute javac. It gives you much more control and returns usable information
回答5:
I know Open the explorer:Runtime.getRuntime().exec("explorer");
so I guess Runtime.getRuntime().exec("java");
and Runtime.getRuntime().exec("javac");
You can give it a try.
回答6:
I suggest you use Apache Commons Exec, It provides a simple API. Cheers!
回答7:
the best way is to run by invoking os shell and then by passing javac and java tools.
take the result by using inputstream and print it
来源:https://stackoverflow.com/questions/12402547/how-to-execute-javac-and-java-commands-from-java-program