`
fsword
  • 浏览: 164687 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

jruby下使用nokogiri、xslt

阅读更多

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

 

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

 

$ gem list nokogiri
*** LOCAL GEMS ***
nokogiri (1.4.4.2 java)

 

不过,实际使用的时候还有一个问题,它需要有xslt哭的支持,否则就会出错:

 

$ rails s
/home/john/.rvm/rubies/jruby-1.5.6/lib/ruby/site_ruby/shared/ffi/library.rb:28:in `ffi_lib': Could not
 open library 'xslt' : xslt: cannot open shared object file: No such file or directory. Could not open 
library 'libxslt.so' : libxslt.so: cannot open shared object file: No such file or directory (LoadError)
	from /home/john/.rvm/rubies/jruby-1.5.6/lib/ruby/site_ruby/shared/ffi/library.rb:10:in `map'
	from /home/john/.rvm/rubies/jruby-1.5.6/lib/ruby/site_ruby/shared/ffi/library.rb:10:in `ffi_lib'
	from /home/john/.rvm/gems/jruby-1.5.6/gems/nokogiri-1.4.4.2-java/lib/nokogiri/ffi/libxml.rb:13
	from /home/john/.rvm/gems/jruby-1.5.6/gems/nokogiri-1.4.4.2-java/lib/nokogiri/ffi/libxml.rb:239
:in `require'
 

 

但是 ruby-xslt 是不能用在这里的,因为它也不是纯ruby库,因此不能用在jruby上

 

$ gem install ruby-xslt
Building native extensions.  This could take a while...
ERROR:  Error installing ruby-xslt:
	ERROR: Failed to build gem native extension.

        /home/john/.rvm/rubies/jruby-1.5.6/bin/jruby extconf.rb
WARNING: JRuby does not support native extensions or the `mkmf' library.
         Check http://kenai.com/projects/jruby/pages/Home for alternatives.
extconf.rb:31: undefined method `enable_config' for main:Object (NoMethodError)
 

最后找到的是这个库:

 

$ gem install saxony
Fetching: saxony-0.3.3.gem (100%)
Successfully installed saxony-0.3.3
1 gem installed
Installing RDoc documentation for saxony-0.3.3...
$ rails s
=> Booting WEBrick
=> Rails 3.0.5 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-05-21 11:16:11] INFO  WEBrick 1.3.1
[2011-05-21 11:16:11] INFO  ruby 1.8.7 (2010-12-03) [java]
[2011-05-21 11:16:16] INFO  WEBrick::HTTPServer#start: pid=3755 port=3000
 

ok,现在可以用 nokogiri 了

0
0
分享到:
评论

相关推荐

    如何安装与配置JRuby

    本文介绍了JRuby的安装与配置。JRuby的安装需要JRuby以及JDK,本文使用的版本分别是JRuby 1.1.2以及Java 1.6。至于JRuby配置,文章主要介绍了测试JRuby安装的方法。

    jruby_windows1.7and bin1.7

    jruby安装包 和 jruby的lib库 JRuby是面向Ruby、基于Java虚拟机(JVM)的一种解释程序,它结合了Ruby语言的简易性和功能强大的JVM的执行机制,包括与Java库 全面集成。Rails彻底加快及简化了Web应用的开发,不过它让...

    weka-jruby:使用JRuby进行机器学习和数据挖掘

    请参阅以获取有关如何将Weka与JRuby结合使用以及一些示例代码片段的详细信息。 发展 使用git clone git@github.com:paulgoetze/weka-jruby.git查看回购。 设置本地环境变量export JARS_VENDOR=fal

    使用JRuby开发Web Service全攻略

    本文介绍了如何用JRuby开发Web Service。用JRuby开发Web Service,需要安装ActionWebService。安装完毕之后便可以开始调用及部署了。

    jruby1.7.8版本呢

    jruby是一个ruby的解析器,可将ruby解析为java文件,jruby作为ruby解析器时刻调用java代码

    jruby开发----jar

    jruby与java使用开发,听说jruby能是swing的调用变为更简单

    jruby-complete-1.7.19.jar

    jruby-complete-1.7.19.jar,java版本的ruby解析器

    jruby-1.3.1.jar

    jruby-1.3.1.jar包 解决org.jruby.exceptions.JumpException 等报错

    Deploying.with.JRuby.9k.Deliver.Scalable.Web.Apps.Using.JVM

    This book introduces you to three JRuby deployment strategies that give you the performance and scalability you need, while you use a language designed for rapid development. Explore common ...

    JRuby语言实战技术

    JRuby语言实战技术,java下运用ruby

    jruby-src-1.0

    jruby-src-1.0.zip

    JRuby+Swing是开发人员钟情的选择

    JRuby是用于Java平台的一个Ruby实现。它使您可以通过JVM执行Ruby代码。在JRuby下运行的Ruby代码还可以装载和使用Java库,包括Swing。所以JRuby+Swing的组合,也成为了开发人员的选择之一。

    JRuby在Java测试中的应用

    JRuby在Java测试中的应用,使用脚本语言,高效快进行Java程序测试。

    org.jruby.rar

    org.jruby.rar

    jruby-bin-1.3.1.zip

    jruby-bin-1.3.1.zip 用于jruby语言研发的必要工具

    JRuby window X64 开发软件

    JRuby window X64 开发软件

    jruby-complet-1.7.zip

    找不到或无法加载主类org.jruby.Main。 原因是/usr/local/hbase/lib 目录下没有jruby-complete-1.7.19.jar文件.,下载本文件,解压缩后将jar文件直接添加到/usr/local/hbase/lib 目录下。

    jRuby On Rails WEB2.0

    jRuby On Rails WEB 2.0

    Using JRuby.pdf.英文原版. JRuby教程

    Now you can bring the best of Ruby into the world of Java, with Using JRuby. Come to the source for the JRuby core team’s insights and insider tips. You’ll learn how to call Java objects seamlessly ...

    请放弃 Jruby和Jython 而选择 Groovy

    对于Jruby、Jython和Groovy三种动态语言,长期以来很多人犹豫于如何选择它们。本文提出一个非常有力的例证证明:如果你是一个基于Java虚拟机的开发者,那么请放弃Jruby和Jython。

Global site tag (gtag.js) - Google Analytics