Reputation: 83
I want my java program to execute a different java program. I used following method.
(The program I want to run is Example.java)
class RunJava
{
public static void main(String a[])throws Exception
{
Runtime.getRunTime().exec("c:\\"+path+"\\javac Example.java");
Runtime.getRunTime().exec("c:\\"+path+"\\java Example");
}
But it is not working. Is there any other way of doing this?
Upvotes: 0
Views: 175
Reputation: 3753
please refer how to compile & run java program in another java program?. Same solution available !!
Upvotes: 1
Reputation: 504
Why don't you create an executable jar for the Example.java and place it in the path then execute it with:
Runtime.getRunTime().exec("c:/"+path+"/java -jar Example.jar");
Upvotes: 0