<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Depth-First: Scripting Java with Ruby: Yet Another Java Bridge</title>
    <link>http://depth-first.com/articles/2006/10/25/scripting-java-with-ruby-yet-another-java-bridge</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Walking the Web of Chemical Informatics</description>
    <item>
      <title>Scripting Java with Ruby: Yet Another Java Bridge</title>
      <description>&lt;p&gt;&lt;img src="http://depth-first.com/files/ruby_logo_new.gif" align="right"&gt;&lt;/img&gt;New technologies attempting to compete with older technologies need to provide a clear upgrade path, if they are to succeed. A case in point is Ruby. Many Java developers' reaction to this language has less to do with its capabilities and more to do with previous investments in Java. What good is a new language if the special library X that you depend on needs to be rewritten from scratch?&lt;/p&gt;

&lt;p&gt;Previous articles, starting with &lt;a href="http://depth-first.com/articles/2006/08/26/scripting-java-libraries-with-ruby-java-bridge"&gt;this one&lt;/a&gt;, have discussed &lt;a href="http://rjb.rubyforge.org"&gt;Ruby Java Bridge&lt;/a&gt; (RJB) as a Java-Ruby integration tool. Two additional articles discussed RJB in the context of &lt;a href="http://depth-first.com/articles/2006/10/24/metaprogramming-with-ruby-mapping-java-packages-onto-ruby-modules"&gt;mapping Java packages onto Ruby modules&lt;/a&gt; and &lt;a href="http://depth-first.com/articles/2006/10/12/running-ruby-java-bridge-on-windows"&gt;Java-Ruby integration on Windows&lt;/a&gt;. RJB currently provides the mechanism whereby the full &lt;a href="http://cdk.sf.net"&gt;Chemistry Development Kit&lt;/a&gt; (CDK) API can be used in Ruby with &lt;a href="http://rubyforge.org/projects/rcdk"&gt;Ruby CDK&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Another option for Java-Ruby integration is &lt;a href="http://jruby.codehaus.org/"&gt;JRuby&lt;/a&gt;, a Java implementation of the Ruby interpreter. JRuby offers tight integration with the Java Virtual Machine, which will be ideal in many situations. In other situations, it will not be the best choice. For example, one of the advantages of RJB over JRuby is that the standard C-Ruby implementation can be used. This in turn offers, for example, full &lt;a href="http://www.rubyonrails.org/"&gt;Rails&lt;/a&gt; functionality and access to C extensions. A disadvantage of RJB is that, being written in C, it requires a working build toolchain for installation.&lt;/p&gt;

&lt;p&gt;I've seen &lt;a href="http://www.jaredrichardson.net/blog/2006/09/01/"&gt;one report&lt;/a&gt; of a Macintosh installation of RJB that failed. Without a Mac of my own, I can't confirm if this is indeed a problem. But this report also pointed me to a third approach to Ruby-Java integration, &lt;a href="http://www.cmt.phys.kyushu-u.ac.jp/~M.Sakurai/cgi-bin/fw/wiki.cgi?page=YAJB"&gt;Yet Another Java Bridge&lt;/a&gt; (YAJB). YAJB is different from both JRuby and RJB in that it extends the C implementation of Ruby with a Java bridge written in pure Java. In theory, it should run on any platform that both Ruby and Java run on.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.cmt.phys.kyushu-u.ac.jp/~M.Sakurai/java/ruby/yajb-0.8.1.tar.gz"&gt;YAJB-0.8.1&lt;/a&gt; installed on my system without a hitch. From the root directory of the distribution:&lt;/p&gt;

&lt;div class="console"&gt;
&lt;pre&gt;
# ruby setup.rb
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Using YAJB was straightforward. A Java &lt;tt&gt;Vector&lt;/tt&gt; instance could be instantiated and manipulated using familiar syntax:&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;yajb/jbridge&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
&lt;span class="ident"&gt;include&lt;/span&gt; &lt;span class="constant"&gt;JavaBridge&lt;/span&gt;

&lt;span class="ident"&gt;v&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;jnew&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;java.util.Vector&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;

&lt;span class="ident"&gt;v&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;add&lt;/span&gt;&lt;span class="punct"&gt;(&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;one&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;)&lt;/span&gt;
&lt;span class="ident"&gt;v&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;add&lt;/span&gt;&lt;span class="punct"&gt;(&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;two&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;)&lt;/span&gt;
&lt;span class="ident"&gt;v&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;size&lt;/span&gt; &lt;span class="comment"&gt;# =&amp;gt; 2&lt;/span&gt;
&lt;span class="ident"&gt;v&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;elementAt&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="number"&gt;1&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt; &lt;span class="comment"&gt;# =&amp;gt; &amp;quot;two&amp;quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Good integration tools can make the difference between actually using new technologies and simply observing them. Java developers interested in using Ruby now have at least three good options to choose from: JRuby; RJB; and YAJB.&lt;/p&gt;</description>
      <pubDate>Wed, 25 Oct 2006 14:53:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:65a72a41-d6a6-4728-82b4-c93b9fed8421</guid>
      <author>Rich Apodaca</author>
      <link>http://depth-first.com/articles/2006/10/25/scripting-java-with-ruby-yet-another-java-bridge</link>
      <category>Tools</category>
      <category>ruby</category>
      <category>java</category>
      <category>integration</category>
      <category>rjb</category>
      <category>jruby</category>
      <category>yajb</category>
    </item>
  </channel>
</rss>
