Groovy为什么即使在我的PATH上也找不到该程序? [英] Why can't Groovy find this program even though it's on my PATH?

查看:151
本文介绍了Groovy为什么即使在我的PATH上也找不到该程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

tl; dr::当我尝试从类执行shell命令时,Groovy无法找到程序(phantomjs,位于我的$PATH上)–否则,它只会找到它可以从Groovy控制台或Grails CLI脚本执行.有什么作用?

tl;dr: Groovy cannot find a program (phantomjs, which is on my $PATH) when I attempt to execute the shell command from a class -- it's otherwise finds it just fine from the Groovy Console or from a Grails CLI script. What gives?

我们有一个Grails脚本,可以在PhantomJS(无头WebKit")中执行JavaScript单元测试.当这些测试在独立脚本(称为grails test-js)中执行时,一切正常. Grails/Gant脚本中的相关行是:

We have a Grails script to execute JavaScript unit tests in PhantomJS ("the headless WebKit"). When these tests are executed in a stand-alone script (call it grails test-js) things work just fine. The relevant line from the Grails/Gant script was:

// 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抱怨说:

But since we want this to run as part of the usual grails test-app cycle, we created an implementation of org.codehaus.groovy.grails.test.GrailsTestType. When we get to the part in that implementation where we need to execute the tests, that same code (as above) doesn't work, and Groovy/Grails complains that:

java.io.IOException: Cannot run program "phantomjs": error=2, No such file or directory

我的第一个想法是phantomjs不在我的$PATH上-但我知道它已经出现了,并且再次:当从Grails/Gant脚本运行时,它起作用了.因此,我在Groovy控制台中进行了尝试,然后从那里开始就可以了.

My first thought was that phantomjs was not on my $PATH -- but I know that it is, and again: it worked when run from the Grails/Gant script. So I tried it in the Groovy Console, and it works OK from there.

现在,如果我从phantomjs切换到/absolute/path/to/phantomjs,则可以正常工作.但是将绝对文件系统路径硬编码到类中并不是解决方案.

Now, if I switch from phantomjs to /absolute/path/to/phantomjs, then it works fine. But hard-coding an absolute filesystem path into the class cannot be the solution.

所以:为什么Groovy在这种情况下不能找到phantomjs?

So: why isn't Groovy finding phantomjs under those circumstances?

更新:我怀疑这可能与我的IDE(IntelliJ Idea)有关,因为从命令行运行此错误似乎没有发生.

Update: I suspect that this might have something to do with my IDE (IntelliJ Idea), as this error doesn't appear to be happening when running this from the command line.

推荐答案

事实证明,这与尝试从我的IDE(IntelliJ IDEA)内运行测试有关,更具体地说,与此有关.在OS X计算机上.

As it turns out, this had everything to do with trying to run the tests from within my IDE (IntelliJ IDEA) and, more specifically, trying to do this on an OS X machine.

解决方案是使用launchd.confphantomjs添加到我的PATH中.我...

The solution was to add phantomjs to my PATH using launchd.conf. I...

  1. 创建了/etc/launchd.conf
  2. 向其添加了以下行:(注意:我使用 Homebrew 安装了PhantomJS)

  1. created /etc/launchd.conf
  2. added the following line to it: (note: I installed PhantomJS with Homebrew)

setenv PATH /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

所有测试都成功运行.

这篇关于Groovy为什么即使在我的PATH上也找不到该程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆