【问题标题】:Groovy script to run grails command运行 grails 命令的 Groovy 脚本
【发布时间】:2013-11-21 01:19:30
【问题描述】:

我想创建一个 groovy 脚本来运行 grails clean、grails compile 和 grails run-app,但是,我注意到我无法运行任何 grails 命令。事实上,我尝试在 Groovy 控制台上运行以下脚本:

 def envs = System.getenv().collect{"$it.key=$it.value"}
    //println envs
    println "java -version".execute(envs, new File("c:\\")).err.text
    println "grails -version".execute(envs, new File("c:\\")).text

这本身给了我以下输出:

groovy> def envs = System.getenv().collect{"$it.key=$it.value"} 
groovy> //println envs 
groovy> println "java -version".execute(envs, new File("c:\\")).err.text 
groovy> println "grails -version".execute(envs, new File("c:\\")).text 


    java version "1.7.0_06"
    Java(TM) SE Runtime Environment (build 1.7.0_06-b24)
    Java HotSpot(TM) 64-Bit Server VM (build 23.2-b09, mixed mode)

    Exception thrown

    java.io.IOException: Cannot run program "grails" (in directory "c:\"): CreateProcess error=2, The system cannot find the file specified

        at ConsoleScript26.run(ConsoleScript26:4)

    Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified

        ... 1 more

以前有人遇到过这个问题吗?

【问题讨论】:

    标签: java grails groovy


    【解决方案1】:

    在 Windows 上,grails 命令是一个.bat 文件,您不能直接使用Runtime.execProcessBuilder 运行.bat 文件(这是"...".execute 最终委托给的)。

    使用cmd /c:

    println ["cmd", "/c", "grails -version"].execute(envs, new File("c:\\")).text
    

    或者可能

    println ["cmd", "/c", "grails", "-version"].execute(envs, new File("c:\\")).text
    

    我不确定“grails -version”是需要一个参数还是两个参数(可能两种方式都有效,我目前无法对此进行测试)。

    【讨论】:

      【解决方案2】:

      如果java - version 运行而grails -version 没有运行,则意味着您没有更新PATH 环境变量。将bin 文件夹的位置附加到变量中。

      由于 Grails 只是一个 zip,因此您需要手动完成。

      【讨论】:

        猜你喜欢
        • 2013-09-14
        • 2015-10-01
        • 1970-01-01
        • 2017-05-28
        • 2015-12-19
        • 2018-02-05
        • 2021-07-27
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多