views:

314

answers:

2
+2  Q: 

run jar in eclipse

Hi!

My problem is that I want to run some jar files in eclipse within a plugin. This jars make analysis on an eclipse project:

String run_tool ="cmd.exe /C start java -Xmx400m -cp org-jcolumbus.jar;org-jcolumbus-schema.jar;lib/antlr.jar org.jcolumbus.tool.BuildModel -tasks "+src_dir+" -jsi "+SelProj.getLocation()+"/result/temp/"+SelProj.getName();
Runtime rt2 = Runtime.getRuntime();
Process sp2 = rt2.exec(run_tool);

"src_dir" is source dir of the eclipse project

"SelProj.getLocation()+"/result/temp/"+SelProj.getName()" is a result dir in the selected eclipse project, the results come here.

After the jars' running, I want to rename the "temp" folder to other one, but the eclipse renames the "temp" folder before the jars finish the running, so the jars don't work fairly.

I try to use the sp2.waitFor() method, but it isn't good. I think the "start" parameter, after cmd.exe /C start in new process, what I can't control.
If anybody has some advice, please give me. Thank's.

+1  A: 

You could use a StreamGobbler (see this SO question or this simple one) to look for the completion of your command before going on with the rest of your program.

Note: read both standard out and standard error is advised.

Notebis: as this SO answer illustrates, running a 'cmd' without the start might enable the .waitFor() to do what you want.

Process p = Runtime.getRuntime().exec(cmd + " < c:\\someTextFile.txt", null, cmdDir);
...
int errCode = p.waitFor();
VonC
+1  A: 

Try running java without using start:

String run_tool ="cmd.exe /C java ...
Kcats