Running Maven from Java code in Windows?
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
User "mvn.cmd" instead of mvn or mvn.bat. It works fine.
You can view mvn.bat and echo which java command is actually executed and run it directly.
In mvn.bat:
%MAVEN_JAVA_EXE% %MAVEN_OPTS% -classpath %CLASSWORLDS_JAR% "-Dclassworlds.conf=%M2_HOME%\bin\m2.conf" "-Dmaven.home=%M2_HOME%" %CLASSWORLDS_LAUNCHER% %MAVEN_CMD_LINE_ARGS%
In my machine executing dependency:tree is:
"java -classpath \"C:\dev\tools\apache-maven-3.1.1\boot\plexus-classworlds-2.5.1.jar\" -Dclassworlds.conf=C:\dev\tools\apache-maven-3.1.1\bin\m2.conf -Dmaven.home=\"C:\dev\tools\apache-maven-3.1.1\" org.codehaus.plexus.classworlds.launcher.Launcher dependency:tree"