Blog

JRuby: Saint Valentine, Bless Java and Ruby

Denis Petruchik

JRuby

In January, the JRuby community announced the 1.6.0.RC1 release of JRuby, a Java implementation of the Ruby programming language. Since we already utilized this tool in one of our Java projects, the release encouraged me to take a deeper look at it and reveal its strong sides and hidden issues.

What is JRuby?

Well, JRuby is the interpreter of the Ruby programming language that enables building Ruby scripts and Ruby on Rails applications into Java implementations. JRuby features some of the similar concepts Ruby has, including object-oriented programming and duck-typing.

With JRuby, you get most of the Ruby/Rails advantages and enable interoperability with Java platform applications, as well as gain access to the full range of Java functionality.

    1. You can efficiently use Java classes in Ruby scripts.

    2. JRuby can be applied to create solutions for Google App Engine. You can use JRuby as easy as any of the native App Engine languages.

    3. JRuby is compatible with all operating systems that allow for running J2SE 1.5 and higher, which means that it can be used to create cross-platform apps, including desktop ones.

    4. JRuby enables to run Ruby on Rails applications on any Java application server: JBoss, WebLogic, GlassFish, etc.

    5. JRuby can be leveraged to create mobile applications—for the Android platform at the moment—via Scripting Layer for Android (SL4A). SL4A brings scripting languages to Android by allowing developers to edit and execute scripts and interactive interpreters directly on an Android device.

    6. JRuby supports RubyGems, a package manager that allows for installing gems locally and remotely (though C extensions are not supported).

    7. You can access the existing Spring context from JRuby on RoR applications and use it to work with Spring beans, as well as to enable Hibernate without calling ActiveRecord.

    8. Furthermore, JRuby works even faster than Ruby. When I tested Ruby 1.8.7 and JRuby 1.6.0 implementations against each other, the tests showed 4-5 times better performance of JRuby due to the dynamic compilation.

How to use it?

Java developers can still work in the IDE they are used to, say, Eclipse or IntelliJ IDEA. In particular, Eclipse can be utilized along with the RedRails plug-in, while IntelliJ IDEA can be used with Maven, which handles Ruby scripts during the project building. So, IntelliJ IDEA combined with Maven enables to set up a project on any computer, regardless of its OS and libraries installed.

Another tool Java developers can use is Warbler. Warbler is a gem that makes a .war file out of the existing Ruby on Rails application. The intent is to provide a flexible and easy way to pack all application files for deployment to a Java application server.

Things to keep in mind

However, there are still some challenges I noticed when using JRuby:

    1. Though, as I mentioned above, you can successfully enable Java classes in Ruby scripts and call Ruby scripts from Java, there are certain limitations:

    • When using Java APIs in Ruby scripts, it is sometimes necessary to add synchronization on an object for thread safety.
    • Java classes cannot be inherited from Ruby classes.
    • To use a Java class, you have to provide a full path to it (e.g., java.lang.Thread) without using import.

    2. Running JRuby applications takes longer than native Ruby apps, because of the Java Virtual Machine (JVM) launch.

    3. A JRuby application requires more RAM to run several copies compared to Ruby apps.

    4. The JRuby community is not as large as the Ruby community, although they are both tightly connected.

JRuby horizons

With all its strong sides and drawbacks, I think JRuby will take up its niche in the range of technologies Java and Ruby developers use frequently.

It might be a silver bullet in case you need to integrate disparate systems, given that one of them is written in Ruby and another one runs on Java. For example, if companies merge and need to integrate their corporate portals or CRMs for easier maintenance, using JRuby will sure be handy. You can re-use the existing Ruby code and add some functionality from a Java library or vice versa.

Using the Java Virtual Machine, you can also build cross-platform apps in Java. As JRuby provides dynamic invocation on JVM, Ruby developers can create applications for multiple operating systems.

I think that there is a future for using JRuby on mobile platforms, too. As I mentioned before, JRuby currently enables to create applications for Android. It is rumored that it will allow for developing apps for Blackberry in the nearest future. We’ll see. 🙂

No Comments

Download Benchmarks and Research

© 2001 – 2018 Altoros

This site uses cookies for analytics, personalized content and ads. By continuing to browse this site, you agree to this use. Learn more
I agree