I am trying to run maven from my java class based on this suggestion:
How to run maven from java?
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.
I also like this article: http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With