vec*_*tor 2 groovy groovy-console
给定以下目录结构:
/home/some/random/foler/myScript.grooy
...如何在脚本本身中以编程方式获取myScript.grooy父目录的路径?
最终我试图从脚本所在的同一目录中读取几个文件.
编辑:尝试在Windows 7,Groovy 2.0.1,groovy控制台上运行它
Wil*_*ill 13
那么,解决方案是在Java的File类中:
println new File(".").absolutePath
如果你想获得同一目录中的每个groovy脚本,也许你可以使用Groovy JDK中的一些其他工具,例如eachFile:
def files = []
new File(".").eachFile { 
    if (it.name.endsWith(".groovy") ) files << it 
}
println files
如果你想要正在运行的脚本名称,那么你就遇到了问题(http://jira.codehaus.org/browse/GROOVY-1642)
根据JIRA,这是当前的解决方法(并不总是有效):
URL scriptUrl = getClass().classLoader.resourceLoader
    .loadGroovySource(getClass().name)
| 归档时间: | 
 | 
| 查看次数: | 21486 次 | 
| 最近记录: |