在 Eclipse 中运行 jar

发布于 2024-08-12 01:16:24 字数 742 浏览 2 评论 0原文

我的问题是我想在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你穿错了嫁妆 2024-08-19 01:16:24

尝试在不使用 start 的情况下运行 java:

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

Try running java without using start:

String run_tool ="cmd.exe /C java ...
勿忘初心 2024-08-19 01:16:24

您可以使用 StreamGobbler (请参阅此 SO问题或这个简单的)在继续程序的其余部分之前查找命令的完成情况。

注意:建议阅读标准输出和标准错误

注意:正如这个SO答案所示,在没有启动的情况下运行“cmd”可能会使 .waitFor() 执行您想要的操作。

Process p = Runtime.getRuntime().exec(cmd + " < c:\\someTextFile.txt", null, cmdDir);
...
int errCode = p.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.

Process p = Runtime.getRuntime().exec(cmd + " < c:\\someTextFile.txt", null, cmdDir);
...
int errCode = p.waitFor();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文