java程序中执行maven,从Windows中的Java代码运行Maven?

I am trying to run maven from my java class based on this suggestion:

Runtime.getRuntime().exec("mvn");

but I get:

java.io.IOException: Cannot run program "mvn": CreateProcess error=2, The system cannot find the file specified

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

...

any suggestions?

解决方案

Try:

Runtime.getRuntime().exec("cmd \c mvn");

Edit:

In response to the firs question...

Yes. See: Process#getInputStream. Basically you will need to consume the output from the sub-process being created.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值