【发布时间】:2012-09-04 18:41:19
【问题描述】:
tl;dr: 当我尝试从一个类执行 shell 命令时,Groovy 找不到程序(phantomjs,在我的 $PATH 上)——否则它只会找到它从 Groovy 控制台或 Grails CLI 脚本中很好。什么给了?
我们有一个 Grails 脚本可以在 PhantomJS(“无头 WebKit”)中执行 JavaScript 单元测试。当这些测试在独立脚本中执行时(称为grails test-js),一切正常。 Grails/Gant 脚本中的相关行是:
// where 'jsTests' is a List with the paths to each test
def failures = 0
jsTests.each {
Process p = "phantomjs lib/phantom-jasmine/lib/run_jasmine_test.coffee file://${it}".execute()
failures += p.exitValue()
}
但由于我们希望它作为通常的grails test-app 循环的一部分运行,我们创建了org.codehaus.groovy.grails.test.GrailsTestType 的实现。当我们到达实现中需要执行测试的部分时,相同的代码(如上)不起作用,Groovy/Grails 抱怨:
java.io.IOException: Cannot run program "phantomjs": error=2, No such file or directory
我的第一个想法是phantomjs 不在我的$PATH 上——但我知道它确实存在,并且再次:从 Grails/Gant 脚本运行时它可以工作。所以我在 Groovy 控制台中进行了尝试,从那里可以正常工作。
现在,如果我从phantomjs 切换到/absolute/path/to/phantomjs,那么它工作正常。但是将绝对文件系统路径硬编码到类中并不是解决方案。
那么:为什么在这种情况下 Groovy 没有找到 phantomjs?
更新:我怀疑这可能与我的 IDE(IntelliJ Idea)有关,因为从命令行运行时似乎没有发生此错误。
【问题讨论】:
标签: macos grails groovy intellij-idea phantomjs