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.