How to execute “javac and java commands” from java program?

半城伤御伤魂 提交于 2019-12-02 00:57:21

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!