为JRuby安装hpricot

时间:2009-04-07 15:46:18

标签: ruby-on-rails jruby cucumber webrat hpricot

我正试着在Rails上看Jruby的黄瓜。其中一个预先请求的是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 个答案:

答案 0 :(得分:5)

我不知道黄瓜,但Hpricot肯定可以从JRuby 1.2.0使用(虽然不是最新版本的Hpricot)。你安装了哪个版本的Hpricot?也许它与其他图书馆不兼容?

以下命令对我有用:

jruby -S gem install hpricot --version '~>0.6.1'  

答案 1 :(得分: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

你应该是金色的。

答案 2 :(得分:1)

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

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

答案 3 :(得分:0)

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