How to run Gant targets from within a Grails controller?
Suppose I have a block of Gant code:
target(echo:"test"){
ant.echo(message:"hi")
}
setDefaultTarget("echo")
Th开发者_Go百科is is usually run from a command line.
How could I place the block in a Grails controller and run it from there?
You can use AntBuilder for this:
class FooController {
def index = {
def ant = new AntBuilder()
ant.echo(message:"hi")
}
}
You can create a groovy script say DynaScript_.groovy that contains your Gant code and place this script file in the {grailsHome}/scripts folder.
And then you can invoke the script file from your controller like this:
class FooController {
def index = {
def process = "cmd /c grails dyna-script".execute()
def out = new StringBuilder()
process.waitForProcessOutput(out, new StringBuilder())
println "$out"
}
}
It's important that your script name ends with an underscore.
精彩评论