Groovy 脚本运行


1)通过命令行运行

通过命令行运行脚本,需要现将 groovy/bin 加入到系统变量,此时就可以随处通过 groovy.bat/groovy.sh 运行 groovy 脚本;

groovy foo/MyScript.groovy [arguments]

如运行脚本 hello.groovy:

println "Hi, ${args[0]} welcome to Groovy!"

执行命令行:

$ groovy Hi.groovy assad

2)使用 groovy 创建 Unix 脚本

如编写以下 groovy 脚本:hello.groovy

#!/usr/bin/env groovy
println("this is groovy script")
println("Hi,"+args[0]+" welcome to Groovy")

执行以下命令

$ chmod +x hello.groovy
$ ./hello.groovy assad