From: Jason Foreman Date: 2005-06-22T00:08:37+09:00 Subject: Re: Ruby and Java On 6/21/05, Wayne Pierce wrote: > I have a vendor product with Java APIs that I need to write against > and would like to use Ruby. > > Does anyone have an opinion on the most reliable way to interact with > Java from Ruby? I've seen some different projects, but can't tell if > there is any major difference between how they are implemented or > which are actively maintained. > > Thanks, > > Wayne > > Two main options: RJB [1], and JRuby [2]. RJB (RubyJava Bridge) is an extension to the standard Ruby interpreter that lets you communicate with a Java VM via JNI. It works pretty well, but can be a bit 'low level' sometimes, due to the nature of its implementation. IE, sometimes you need to know how to construct java method signatures and such (not a big deal) JRuby is a complete Ruby interpreter written in Java, so all your Ruby code runs in the JVM. This has advantages that the classes can have a tighter relationship, however the implementation is currently a little slow, and partially incomplete. Also, you lose the ability to use Ruby libraries and extensions written in C. I've used RJB for a project in order to use the JasperReports library, and had pretty decent success. It can be difficult to do proper error handling, because you have both Ruby errors and Java exceptions to deal with. But it is certainly feasible. It works best when you simply want to call some java code from ruby, and get the result. When you start wanting to have ruby classes inherit from java classes, and have java callback to ruby which calls back to java, it can get messy. Just try to keep it as simple as possible. Jason [1] http://arton.no-ip.info/collabo/backyard/?RubyJavaBridge [2] http://jruby.sourceforge.net