Reputation: 1120
Is there any way to execute "javac and java commands" from java program?
If so,please help me out....
Upvotes: 5
Views: 9807
Reputation: 1
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
Upvotes: 0
Reputation: 195
I suggest you use Apache Commons Exec, It provides a simple API. Cheers!
Upvotes: 0
Reputation: 1
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.
Upvotes: 0
Reputation: 3353
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
Upvotes: 0
Reputation: 15479
You can use the ProcessBuilder class
ProcessBuilder pb =
new ProcessBuilder("javac", "arg1, "arg2");
Upvotes: 1
Reputation: 6783
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.
Upvotes: 3