简体   繁体   English

从RunTime.exec()执行Java命令的正确方法是什么

[英]What is the correct way of executing a java command from RunTime.exec()

I need to run command using Runtime.exec() : 我需要使用Runtime.exec()运行命令:

java -cp .:/s/v-lib/* tDesigner -inRs /scg.rsp -out /g.plan;

here i need to add all the jars present in /s/v-lib directory to my class path. 在这里,我需要将/ s / v-lib目录中存在的所有jar添加到我的类路径中。 Do i need to add them individually? 我需要单独添加它们吗?

tDesigner is my class. tDesigner是我的课程。
-inRs /scg.rsp -out /g.plan are the arguments to the class. -inRs /scg.rsp -out /g.plan是该类的参数。

what will be the correct way to construct command string? 构造命令字符串的正确方法是什么?
is this correct: 这个对吗:

String[] command = {"java", "-cp", ".:/s/v-lib/*", "tDesigner" ,"-inRs", "/scg.rsp" ,"-out", "g.plan"};

The invocation of exec() looks correct. exec()的调用看起来正确。

Regarding the classpath, since java 1.5 you may specify a directory (rather than jars) in the classpath, in which case all jars found there are added to the classpath. 关于类路径,从Java 1.5开始,您可以在类路径中指定目录 (而不是jar),在这种情况下,找到的所有jar都将添加到类路径中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM