Thrift gem and JRuby

2019-07-16 13:49发布

问题:

I just recently installed JRuby and the Thrift gem after using it in MRI. I'm running into a problem where if I require 'thrift' I get the message "Unable to load thrift_native extension. Defaulting to pure Ruby libraries." If I then try and require the code thrift generated in ruby I'll get this error: "NameError: uninitialized constant Thrift::Struct_Union"

Is the thrift gem currently not working with JRuby?

Is there something I can do to use thrift with JRuby besides using the gem?

EDIT: After digging around on my mac, I found that the MRI gem and JRuby gem are different even though the gems are the same version (0.2.0.4). Now this seems like a terrible idea, but if you copy the .rb files from the MRI gem into the JRuby gem and add require 'thrift/struct_union' to thrift.rb you will no longer get any errors related to the Thrift gem except that it can't find thirft_native and will use pure Ruby libraries. This can be explained since thrift_native is made for C not Java.

回答1:

When you're already using JRuby, I would use a Java native thrift client. For me, thrift was the reason for moving to JRuby in the first place, since the Ruby implementation is rather slow and buggy.