Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 运行grails命令的Groovy脚本_Java_Grails_Groovy - Fatal编程技术网

Java 运行grails命令的Groovy脚本

Java 运行grails命令的Groovy脚本,java,grails,groovy,Java,Grails,Groovy,我想创建一个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

我想创建一个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-version
运行而
grails-version
未运行,则表示您没有更新
路径
环境变量。将位置附加到变量的
bin
文件夹中


由于Grails只是一个zip文件,您需要手动执行。

在Windows上,
Grails
命令是一个
.bat
文件,您不能直接使用
Runtime.exec
ProcessBuilder
(这就是
“…”运行
.bat
文件。执行
最终会委托给您

使用
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”是否需要一个参数或两个参数(可能是两种方法都可以,我目前无法测试这一点)