svkvvenky
svkvvenky

Reputation: 1120

How to execute "javac and java commands" from java program?

Is there any way to execute "javac and java commands" from java program?
If so,please help me out....

Upvotes: 5

Views: 9807

Answers (7)

ketansushanth.Kgv
ketansushanth.Kgv

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

Amine
Amine

Reputation: 195

I suggest you use Apache Commons Exec, It provides a simple API. Cheers!

Upvotes: 0

youngto
youngto

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

Germann Arlington
Germann Arlington

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

munyengm
munyengm

Reputation: 15479

You can use the ProcessBuilder class

 ProcessBuilder pb =
   new ProcessBuilder("javac", "arg1, "arg2");

Upvotes: 1

Sujay
Sujay

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

Michael Laffargue
Michael Laffargue

Reputation: 10304

Like Runtime.getRuntime().exec("javac ..."); ?

Upvotes: 12

Related Questions