从grails项目执行gant脚本

时间:2014-02-14 17:12:20

标签: grails groovy gant

我编写了自己的gant脚本,从命令行运行良好。现在我需要从这样的grails项目运行这个脚本:

def outputMessage

try{

    GroovyScriptEngine engine = new GroovyScriptEngine("/www", this.getClass().getClassLoader());
    engine.run("scripts/MyOwnScript_.groovy", "param1 param2")
    outputMessage = "<br> OK: Script run successfully"
}
catch (Exception e) {
    outputMessage += "<br> ERROR: There has been running the script"
}

我得到的错误是“No such property:includeTargets for class:MyOwnScript_”,因为我的gant脚本需要一些其他脚本。

有人知道让它运作的正确方法吗?

2 个答案:

答案 0 :(得分:0)

您是否尝试获取脚本文件夹的路径并执行外部过程,如

["groovy", "scripts/MyOwnScript_.groovy", "param1", "param2"].execute()

有关在groovy中运行外部进程的更多信息,请参阅here

答案 1 :(得分:0)

回答我自己的问题。主要问题是我需要使用如下所示的完整路径来运行grails:

Map<String, String> env = System.getenv()
final processBuilder = new ProcessBuilder()
processBuilder.directory(new File("folderFromWhereIWantToRunTheGantScript"))
processBuilder.command([env['GRAILS_HOME']+"/bin/grails","MyOwnScript param1 param2"])
println processBuilder.directory()
Process proc = processBuilder.start()
proc.consumeProcessOutput(out, err)

proc.waitFor()