免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3531 | 回复: 1
打印 上一主题 下一主题

jruby下使用nokogiri、xslt [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-05-23 12:41 |只看该作者 |倒序浏览
jruby下使用nokogiri、xslt




jruby与原生的ruby vm之间最大的区别是多了一个jvm作为中间层,好处是可以借助成熟的java 虚拟机技术,缺点就是不能象以前那样使用很多本地编译的动态链接库,这个问题的解决只能靠为这些库开发java版本来搞定。



例如,很多ruby开发者都喜欢nokogiri这个库,它处理html、xml非常方便,但是之前它是基于本地库的,所以jruby环境下不好用,不过现在有了 java 版本



Bash代码
  1. $ gem list nokogiri
  2. *** LOCAL GEMS ***
  3. nokogiri (1.4.4.2 java)
复制代码
不过,实际使用的时候还有一个问题,它需要有xslt哭的支持,否则就会出错:



Bash代码
  1. $ rails s
  2. /home/john/.rvm/rubies/jruby-1.5.6/lib/ruby/site_ruby/shared/ffi/library.rb:28:in `ffi_lib': Could not
  3. open library 'xslt' : xslt: cannot open shared object file: No such file or directory. Could not open
  4. library 'libxslt.so' : libxslt.so: cannot open shared object file: No such file or directory (LoadError)
  5.         from /home/john/.rvm/rubies/jruby-1.5.6/lib/ruby/site_ruby/shared/ffi/library.rb:10:in `map'
  6.         from /home/john/.rvm/rubies/jruby-1.5.6/lib/ruby/site_ruby/shared/ffi/library.rb:10:in `ffi_lib'
  7.         from /home/john/.rvm/gems/jruby-1.5.6/gems/nokogiri-1.4.4.2-java/lib/nokogiri/ffi/libxml.rb:13
  8.         from /home/john/.rvm/gems/jruby-1.5.6/gems/nokogiri-1.4.4.2-java/lib/nokogiri/ffi/libxml.rb:239
  9. :in `require'
复制代码
但是 ruby-xslt 是不能用在这里的,因为它也不是纯ruby库,因此不能用在jruby上



Bash代码
  1. $ gem install ruby-xslt
  2. Building native extensions.  This could take a while...
  3. ERROR:  Error installing ruby-xslt:
  4.         ERROR: Failed to build gem native extension.

  5.         /home/john/.rvm/rubies/jruby-1.5.6/bin/jruby extconf.rb
  6. WARNING: JRuby does not support native extensions or the `mkmf' library.
  7.          Check http://kenai.com/projects/jruby/pages/Home for alternatives.
  8. extconf.rb:31: undefined method `enable_config' for main:Object (NoMethodError)  
复制代码
最后找到的是这个库:



Bash代码
  1. $ gem install saxony
  2. Fetching: saxony-0.3.3.gem (100%)
  3. Successfully installed saxony-0.3.3
  4. 1 gem installed
  5. Installing RDoc documentation for saxony-0.3.3...
  6. $ rails s
  7. => Booting WEBrick
  8. => Rails 3.0.5 application starting in development on http://0.0.0.0:3000
  9. => Call with -d to detach
  10. => Ctrl-C to shutdown server
  11. [2011-05-21 11:16:11] INFO  WEBrick 1.3.1
  12. [2011-05-21 11:16:11] INFO  ruby 1.8.7 (2010-12-03) [java]
  13. [2011-05-21 11:16:16] INFO  WEBrick::HTTPServer#start: pid=3755 port=3000  
复制代码
ok,现在可以用 nokogiri 了

论坛徽章:
0
2 [报告]
发表于 2011-05-23 12:55 |只看该作者
支持村艹啊。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP