Problem with BSON for jruby

Hi

I am having trouble with a rubygem called BSON

the code I am running in IRB

jruby-1.4.0 :001 > require ‘rubygems’
=> true
jruby-1.4.0 :002 > require ‘bson’
=> true
jruby-1.4.0 :003 > doc = {:hello => “world”}
=> {:hello=>“world”}
jruby-1.4.0 :004 > bson = BSON.serialize(doc).to_s

after doing this I get the following error

NameError: cannot link Java class org.jbson.RubyBSONEncoder, probable
missing dependency: Bad version number in .class file
from
/Users/benf/.rvm/rubies/jruby-1.4.0/lib/ruby/1.8/irb/ruby-token.rb:46:in
const_missing' from /Users/benf/.rvm/gems/jruby-1.4.0/gems/bson-1.2.4-java/lib/../lib/bson/bson_java.rb:9:inserialize’
from
/Users/benf/.rvm/gems/jruby-1.4.0/gems/bson-1.2.4-java/lib/bson.rb:33:in
serialize' from (irb):5:inirb_binding’
Maybe IRB bug!!

Are there any fixes

It sounds like the bson native extension was compiled with a later
version of Java than you are using (e.g. you are running with Java 5
and bson was compiled with Java 6). For JRuby we compile against Java
5 to avoid this issue…Maybe bson maintainer can re-release compiled
against Java 5 (preferred) … or … you can download and use Java 6.

-Tom

On Fri, Mar 25, 2011 at 6:47 AM, Benjamin F. [email protected]
wrote:

jruby-1.4.0 :003 > doc = {:hello => “world”}
/Users/benf/.rvm/rubies/jruby-1.4.0/lib/ruby/1.8/irb/ruby-token.rb:46:in


blog: http://blog.enebo.com twitter: tom_enebo
mail: [email protected]

Problem solved

Uninstalled both mongo and bson gems

Downloaded and compiled

https://github.com/mongodb/mongo-ruby-driver

ran the rake file

rake gem:install
rake gem:build_all

Then re-install both the mongo and bson gem making sure that it was
getting it from local

gem install mongo
gem install bson-jruby -v 1.2.4 --local

The code above then worked

Try upgrading JRuby and/or bson gem.

$ jruby -S irb
irb(main):001:0> require ‘rubygems’
=> true
irb(main):002:0> require ‘bson’
=> true
irb(main):003:0> doc = {:hello => “world”}
=> {:hello=>“world”}
irb(main):004:0> bson=BSON.serialize(doc).to_s
=> “\026\000\000\000\002hello\000\006\000\000\000world\000\000”
irb(main):005:0> JRUBY_VERSION
=> “1.6.0”
irb(main):006:0> RUBY_DESCRIPTION
=> “jruby 1.6.0 (ruby 1.8.7 patchlevel 330) (2011-03-23 3234436) (Java
HotSpot™ 64-Bit Server VM 1.6.0_24) [darwin-x86_64-java]”
irb(main):007:0> BSON::VERSION
=> “1.2.4”

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs