简体   繁体   English

通过java代码执行jar cvf命令(使用Runtime.exec()方法)

[英]Execute jar cvf command by java code ( using Runtime.exec() method )

I am using the Java code to execute a bat file to make a war file by the following java code 我正在使用Java代码执行bat文件,以通过以下java代码生成war文件

String command = "cmd /C start C:/processFolder/paas.bat";          
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(command);

which means it will execute the paas.bat file to do some jobs. 这意味着它将执行paas.bat文件来完成一些工作。 There is a command within the paas.bat : paas.bat中有一个命令:

jar cfv xxx.war */ .

however, it does not jar all the file and folder into xxx.war. 但是,它不会将所有文件和文件夹都装入xxx.war。 Does any one has the idea why this happens? 有没有人知道为什么会这样? Thanks! 谢谢!

The command uses current working directory, which will be different from java program. 该命令使用当前工作目录,这与java程序不同。 You may change script to do a cd and then call jar command. 您可以更改脚本以执行CD,然后调用jar命令。

 cd /d <path to folder where this should execute from>
 jar ....

Please capture output , error and exceptions(if any) from the command and add to your question. 请从命令中捕获输出,错误和异常(如果有)并添加到您的问题中。

(note#1. It may be more useful to use tools like ant to do these task. The tasks in ant can be called from java program using ant libraries.. Note#2 - Prefer ProcessBuilder to launch new process. ) (注意#1。使用像ant这样的工具来执行这些任务可能更有用。可以使用ant库从java程序调用ant中的任务。注意#2 - 首选ProcessBuilder启动新进程。)

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

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