从Windows中的Java代码运行Maven? [英] Running Maven from Java code in Windows?
本文介绍了从Windows中的Java代码运行Maven?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想根据这个建议从我的java类运行maven:
I am trying to run maven from my java class based on this suggestion:
How to run maven from java?
Runtime.getRuntime().exec("mvn");
但我得到:
java.io.IOException: Cannot run program "mvn": CreateProcess error=2, The system cannot find the file specified
mvn在我的路径上,我可以从cmd运行它:
mvn is on my path and I can run it just fine from cmd:
C:\Users\m>mvn -v
Apache Maven 3.0.3 (r1075438; 2011-02-28 18:31:09+0100)
Maven home: C:\apache-maven-3.0.3\bin\..
Java version: 1.6.0_20, vendor: Sun Microsystems Inc.
Java home: C:\Program Files\Java\jdk1.6.0_20\jre
...
有任何建议吗?
推荐答案
尝试:
Runtime.getRuntime().exec("cmd \c mvn");
编辑:
回答第一个问题。 。
In response to the firs question...
是的。请参阅: Process#getInputStream 。基本上,你将需要使用正在创建的子流程的输出。
Yes. See: Process#getInputStream. Basically you will need to consume the output from the sub-process being created.
我也喜欢这篇文章: http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
这篇关于从Windows中的Java代码运行Maven?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文