1

我正在尝试查看 Jruby on Rails 的黄瓜。其中一个先决条件是 webrat,它具有先决条件 hpricot。

我已经使用 hpricot 安装了 gem:

gem install hpricot --source http://code.whytheluckystiff.net --version 0.6.1 --platform java

这将安装 hpricot 的 java 版本。我将 hpricot_scan.jar 添加到 CLASSPATH 但是当我运行时:

cucumber features -n

我得到以下输出:

HpricotScanService.java:931:in `hpricot_scan': java.lang.NoSuchMethodError:
org.jruby.runtime.builtin.IRubyObject.getInstanceVariable(Ljava/lang/String;)Lorg/jruby/runtime/builtin/IRubyObject;
from HpricotScanService.java:1324:in `__hpricot_scan'
from null:-1:in `call'
from InvocationCallback.java:67:in `execute'
from FullFunctionCallbackMethod.java:69:in `call'
from DynamicMethod.java:243:in `call'
from CachingCallSite.java:283:in `cacheAndCall'
from CachingCallSite.java:121:in `callBlock'

等等

如果我编译 HpricotScanService.java 文件并将生成的 .class 文件添加到类路径中,我会得到:

Then I should see "Run"
private method `scan' called for Hpricot:Module (NoMethodError)
features/step_definitions/webrat_steps.rb:94:in `/^I should see "([^\"]*)"$/'
features/manage_activity.feature:9:in `Then I should see "Run"'

如果我尝试安装更高版本的 hpricot,那么我会得到:

ERROR: Failed to build gem native extension.
C:/Program Files/Ruby/jruby-1.2.0/bin/../bin/jruby.bat extconf.rb install hpricot --platform java
C:/Program Files/Ruby/jruby-1.2.0/bin/../lib/ruby/1.8/mkmf.rb:7: JRuby does not support native extensions. Check wiki.jruby.org for alternatives. (Not
ImplementedError)
from C:/Program Files/Ruby/jruby-1.2.0/bin/../lib/ruby/1.8/mkmf.rb:1:in `require'
from extconf.rb:1

有没有人知道我做错了什么/没有做什么/我在哪里愚蠢。?

使用 Windows XP、JRuby 1.2.0

4

4 回答 4

5

我不知道黄瓜,但 Hpricot 绝对可以从 JRuby 1.2.0 开始使用(尽管不是最新版本的 Hpricot)。您安装了哪个版本的 Hpricot?也许它与其他库不兼容?

以下命令对我有用:

jruby -S gem install hpricot --version '~>0.6.1'  
于 2009-04-08T20:40:14.123 回答
5

由于 Ola Bini 上个月重写了 hpricot jruby 支持,所以 hpricot 的git head可以安装 jruby 了。只需下载头部,然后使用

jruby -S rake package_jruby
cd pkg
sudo jgem install ./hpricot-0.8.1-jruby.gem

你应该是金色的。

于 2009-08-24T17:13:14.453 回答
1

仅供参考,JRuby 1.4 版现在支持 HPricot 0.7 版。

http://jruby.org/2009/11/02/jruby-1-4-0.html

于 2009-11-19T18:48:29.027 回答
0

HPricot 使用本机 C 扩展,它不符合 FFI。因此它不能在 JRuby 下使用。

于 2009-04-08T01:51:26.227 回答