在 Eclipse 中运行 jar
我的问题是我想在 Eclipse 中的插件中运行一些 jar 文件。此 jar 对 Eclipse 项目进行分析:
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
”是 Eclipse 项目的源目录
“SelProj.getLocation()+”/result/temp/“+SelProj.getName()”
是所选eclipse项目中的结果目录,结果就在这里。
jars运行后,我想将“temp”文件夹重命名为其他文件夹,但eclipse在jars完成运行之前重命名“temp”文件夹,因此jars不能正常工作。
我尝试使用 sp2.waitFor() 方法,但效果不好。我认为“start”参数,在新进程中的cmd.exe /C start
之后,是我无法控制的。
如果有人有任何建议,请给我。谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试在不使用 start 的情况下运行 java:
Try running java without using start:
您可以使用
StreamGobbler
(请参阅此 SO问题或这个简单的)在继续程序的其余部分之前查找命令的完成情况。注意:建议阅读标准输出和标准错误。
注意:正如这个SO答案所示,在没有启动的情况下运行“cmd”可能会使
.waitFor()
执行您想要的操作。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.