guyneo
asked on
How to execute a jar file inside a swing application and wait for completion
Hi Guys,
I am trying to use an existing application in my program. The application is in the form of a jar file. It can take a input from a txt file and spit out a text file as output. I ran this from command prompt and works fine. I need to use this in my program. specify the input txt file and run the jar file. Wait for it to complete and then read& display the output text file.
I really appreciate if you guys can show me how to do this
I am trying to use an existing application in my program. The application is in the form of a jar file. It can take a input from a txt file and spit out a text file as output. I ran this from command prompt and works fine. I need to use this in my program. specify the input txt file and run the jar file. Wait for it to complete and then read& display the output text file.
I really appreciate if you guys can show me how to do this
ASKER
Great!. It looks like it is working. But how do I wait for it and detect when its done.. any idea?
Also I used Runtime.getRuntime().exec instead of Runtime.getSystemRuntime() ; Ic ould not find getSystemRuntime. is it because I am using windows?
Also I used Runtime.getRuntime().exec instead of Runtime.getSystemRuntime()
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Here is the code just for the benefit of those who might need it.
Process proc= Runtime.getRuntime().exec( "YOUR COMMAND ");
try {
proc.waitFor();
} catch (InterruptedException ex) {
System.err.println("Error! !!"+ex.get LocalizedM essage());
}
Process proc= Runtime.getRuntime().exec(
try {
proc.waitFor();
} catch (InterruptedException ex) {
System.err.println("Error!
}
Runtime r = Runtime.getSystemRuntime()
r.exec("java -jar path_to_the_jar");
Quite ugly but it works. A bit nicer solution would be to include the jar within your classpath and call the method of the project that you need here. You could eventually find the main method from this jar in the Manifest.