views:

844

answers:

2

Hello, I'm getting the following error when trying to use Nokogiri with Jruby on Windows 7

D:\code\h4>jruby -e "require 'rubygems'; require 'nokogiri'"
D:/jruby-1.3.1/bin/../lib/ruby/1.8/ffi/library.rb:18:in `ffi_lib': Could not ope
n any of [xml2, xslt, exslt] (LoadError)
        from D:/jruby-1.3.1/lib/ruby/gems/1.8/gems/nokogiri-1.3.3-java/lib/nokog
iri/ffi/libxml.rb:5
        from D:/jruby-1.3.1/lib/ruby/gems/1.8/gems/nokogiri-1.3.3-java/lib/nokog
iri/ffi/libxml.rb:31:in `require'
        from D:/jruby-1.3.1/bin/../lib/ruby/site_ruby/1.8/rubygems/custom_requir
e.rb:31:in `require'
        from D:/jruby-1.3.1/lib/ruby/gems/1.8/gems/nokogiri-1.3.3-java/lib/nokog
iri.rb:10
        from D:/jruby-1.3.1/lib/ruby/gems/1.8/gems/nokogiri-1.3.3-java/lib/nokog
iri.rb:36:in `require'
        from D:/jruby-1.3.1/bin/../lib/ruby/site_ruby/1.8/rubygems/custom_requir
e.rb:36:in `require'
        from -e:1

Seems to be a problem with native extensions (libxml2) incompatibility of Jruby, however I've found a workaround here, but couldn't find libexslt.so and am not sure where to put it. Does anyone have a successful experience of using jruby+windows+nokogiri+libexslt? TIA

+1  A: 

The workaround you found is for a UNIX system; the .so file is a loadable module, similar to a DLL in Windows. And you can't softlink in Windows (the ln -s command), so that doesn't apply in your situation.

Nonetheless, you do have the same problem in that nokogiri can't find your libxml2, libxslt, & libexslt libraries. Since I don't use JRuby or nokogiri, I'm really not sure how it'll work, but my best guess is this:

Most likely, you need Windows binaries (DLLs) of libxml2 and libxslt at a minimum; other related Windows binaries may be needed and are available at the same place. You'll want the DLLs installed somewhere in your path, or better yet in the same directory as your JRuby executable (looks like "D:/jruby-1.3.1/bin"). (If that doesn't work, perhaps a Java-native form of the libraries like libxmlj might work, but I doubt it--you probably need ones native to Windows.)

I expect that will get you on your way to working.

ewall
A: 

It is true that you need the xml2 / libxslt dlls in your path.

However, I have found it necessary to update to jruby-1.4.0RC2 (for some FFI improvements I believe).

Also, need to update to the latest nokogiri 1.3.3 & manually apply the following commit:

http://github.com/tenderlove/nokogiri/commit/0555c69e70083a6368b563f18da2c8d5416515cc

OR install nokogiri from github trunk.

I hope this is helpful.

Useful background links:

h t t p://jira.codehaus.org/browse/JRUBY-3781 h t t p://github.com/tenderlove/nokogiri/issues/closed/#issue/137 h t t p://jira.codehaus.org/browse/JRUBY-4052 h t t p://kenai.com/jira/browse/RUBY_FFI-46

Kevin Compton