I use the Ruby Nokogiri XML parser for to_cctray
Recently I ran into issues when trying to get it running on a Linux machine. This is a quick note on what happened.
This is the setup we had:
$ jruby --version
jruby 1.5.2 (ruby 1.8.7 patchlevel 249) (2010-08-20 1c5e29d) (BEA JRockit(R) 1.5.0_15) [i386-java]
$ jruby -S gem list nokogiri
nokogiri (1.4.3.1)
$ uname -srmpio
Linux 2.6.18-53.el5 x86_64 x86_64 x86_64 GNU/Linux
$ java -version
java version "1.5.0_15"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_15-b04)
BEA JRockit(R) (build R27.6.0-50_o-100423-1.5.0_15-20080626-2104-linux-ia32, compiled mode)
The above gave the following error when to_cctray invoked Nokogiri:
$ jruby -rrubygems start.rb
JRuby limited openssl loaded. http://jruby.org/openssl
gem install jruby-openssl for full support.
I [2010-09-14 20:54:11 $31940] INFO | : activating nokogiri
I [2010-09-14 20:54:12 $31940] INFO | : Installing nokogiri
/home/kinga/jruby-1.5.2/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)
...
I tried experimenting with the JRuby version and the Nokogiri gem version too, but to no avail. Only got another kind of error:
Function 'xsltParseStylesheetDoc' not found in [libxml2.so]
Ultimately the following solved the problem:
$ /opt/bea/jrockit-jdk1.5.0_15_64/bin/java -version
java version "1.5.0_15"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_15-b04)
BEA JRockit(R) (build R27.6.0-50_o-100423-1.5.0_15-20080626-2104-linux-x86_64, compiled mode)
$ JAVA_HOME=/opt/bea/jrockit-jdk1.5.0_15_64/ jruby -rrubygems start.rb
JRuby limited openssl loaded. http://jruby.org/openssl
gem install jruby-openssl for full support.
I [2010-09-14 20:56:18 $402] INFO | : activating nokogiri
I [2010-09-14 20:56:23 $402] INFO | : activating attribute-driven
I [2010-09-14 20:56:23 $402] INFO | : activating retry-this
I [2010-09-14 20:56:23 $402] INFO | : using adapter mongrel (to use another, pass --adapter=<adapter> argument)
I [2010-09-14 20:56:23 $402] INFO | : using port 7000 (to use another, pass --port=<port> argument)
D [2010-09-14 20:56:23 $402] DEBUG | : Using mongrel
...
If you notice carefully, earlier I was using a 32-bit Java version despite the machine being 64-bit (for project-specific reasons). This obviously messed up how Nokogiri via JRuby invoked some native libraries. Forcing a 64-bit Java version for running JRuby fixed the problem and Nokogiri could invoke the native libraries correctly.
That was interesting. This post on stackoverflow gave me a hint of what could be wrong. Perhaps someone could find this post of mine helpful too.