What I want to do is invoke maven from a groovy script. The groovy script in question is used as a maven wrapper to build J2EE projects by downloading a tag and invoking maven on what was downloaded. How should I accomplish invoking maven to build/package the EAR (the groovy script is already capable of downloading the tag from SCM).
A:
You may use Runtime class to launch a shell command. take a look here: http://java.sun.com/javase/6/docs/api/java/lang/Runtime.html#exec(java.lang.String) You may later capture the results of the Process execution (to find out if it failed or not).
Alex Khvatov
2010-04-23 20:15:50
+2
A:
The simplest way to invoke an external process in Groovy is to use the execute() command on a string. For example, to execute maven from a groovy script run this:
"cmd /c mvn".execute()
If you want to capture the output of the command and maybe print it out, you can do this:
print "cmd /c mvn".execute().text
The 'cmd /c' at the start invokes the Windows command shell. Since mvn.bat is a batch script you need this. For Unix you can invoke the system shell.
Chris Dail
2010-04-24 00:09:39
Cool! Didn't know you can do that.
armandino
2010-04-27 05:46:02