0

以下脚本:

#!/opt/groovy-1.8.6/bin/groovy

final env = []

输出:

$ ./small.groovy 
./small.groovy: line 3: final: command not found

需要做什么才能让它作为 Groovy 运行(无需显式调用 Groovy)?

4

1 回答 1

3

我不确定您为什么会看到该错误,但在类 Unix 环境中直接运行 Groovy 脚本的常用方法是使用:

#!/usr/bin/env groovy

println "Hello World"

这样可以确保所有环境变量都正确加载,例如JAVA_HOME.

于 2013-07-01T02:55:13.013 回答