Question

Suppose I have a block of Gant code:

 target(echo:"test"){
    ant.echo(message:"hi")
 }
 setDefaultTarget("echo")

This is usually run from a command line.

How could I place the block in a Grails controller and run it from there?

Was it helpful?

Solution

You can use AntBuilder for this:

class FooController {

   def index = {
      def ant = new AntBuilder()
      ant.echo(message:"hi")
   }
}

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top