JRuby

Java implementation of Ruby


title: "JRuby" type: doc version: 1 created: 2026-02-28 author: "Wikipedia contributors" status: active scope: public tags: ["free-software-programmed-in-java", "free-software-programmed-in-ruby", "jvm-programming-languages", "object-oriented-programming-languages", "ruby-(programming-language)", "scripting-languages", "software-using-the-eclipse-public-license"] description: "Java implementation of Ruby" topic_path: "technology/programming-languages" source: "https://en.wikipedia.org/wiki/JRuby" license: "CC BY-SA 4.0" wikipedia_page_id: 0 wikipedia_revision_id: 0

::summary Java implementation of Ruby ::

::data[format=table title="Infobox software"]

FieldValue
nameJRuby
logo[[Image:JRuby logo.png
developerCharles Oliver Nutter, Thomas Enebo, Ola Bini and Nick Sieger
released
latest release version9.4.12.0
latest release date{{cite web
urlhttps://www.jruby.org/2025/02/11/jruby-9-4-12-0.html
titleJRuby 9.4.12.0 Released
websitejruby.org
date2025-02-11
access-date2025-04-12
programming languageRuby and Java
operating systemCross-platform
platformJava virtual machine
genreRuby programming language interpreter
licenseEPL/GPL/LGPL
::

| name = JRuby | logo = [[Image:JRuby logo.png|200px]] | screenshot = | caption = | developer = Charles Oliver Nutter, Thomas Enebo, Ola Bini and Nick Sieger | released = | latest release version = 9.4.12.0 | latest release date = {{cite web |url=https://www.jruby.org/2025/02/11/jruby-9-4-12-0.html |title=JRuby 9.4.12.0 Released |website = jruby.org |date=2025-02-11 |access-date=2025-04-12 | latest preview version = | latest preview date = | programming language = Ruby and Java | operating system = Cross-platform | platform = Java virtual machine | genre = Ruby programming language interpreter | license = EPL/GPL/LGPL

JRuby is an implementation of the Ruby programming language atop the Java Virtual Machine, written largely in Java. It is free software released under a three-way EPL/GPL/LGPL license. JRuby is tightly integrated with Java to allow the embedding of the interpreter into any Java application with full two-way access between the Java and the Ruby code (similar to Jython for the Python language).

JRuby's lead developers are Charles Oliver Nutter and Thomas Enebo, with many current and past contributors including Ola Bini and Nick Sieger. In September 2006, Sun Microsystems hired Enebo and Nutter to work on JRuby full-time. In June 2007, ThoughtWorks hired Ola Bini to work on Ruby and JRuby.

In July 2009, the JRuby developers left Sun to continue JRuby development at Engine Yard. In May 2012, Nutter and Enebo left Engine Yard to work on JRuby at Red Hat.

History

JRuby was originally created by Jan Arne Petersen, in 2001. At that time and for several years following, the code was a direct port of the Ruby 1.6 C code. With the release of Ruby 1.8.6, an effort began to update JRuby to 1.8.6 features and semantics. Since 2001, several contributors have assisted the project, leading to the current () core team of around six members.

JRuby 1.1 added Just-in-time compilation and Ahead-of-time compilation modes to JRuby and was already faster in most cases than the then-current Ruby 1.8.7 reference implementation.{{cite web | url=http://antoniocangiano.com/2007/12/03/the-great-ruby-shootout/ | title=The Great Ruby Shootout | date=March 12, 2007 | last=Cangiano|first=Antonio | access-date=February 1, 2008}}

JRuby packages are available for most platforms; Fedora 9 was among the first to include it as a standard package at JRuby 1.1.1.{{cite web | url=https://headius.blogspot.com/2008/04/jruby-111-in-redhat-fedora.html | title=JRuby 1.1.1 in RedHat Fedora | date=April 25, 2008 |last=Nutter|first=Charles | access-date=April 26, 2008}} | url=http://admin.fedoraproject.org/pkgdb/packages/name/jruby | title=jruby | publisher=fedoraproject.org | access-date=April 26, 2008

In July 2009, the core JRuby developers at Sun Microsystems, Charles Oliver Nutter, Thomas Enebo and Nick Sieger, joined Engine Yard to continue JRuby development. In May 2012, Nutter and Enebo left Engine Yard to work on JRuby at Red Hat.

JRuby has supported compatibility with Ruby MRI versions 1.6 through 1.9.3. JRuby 1.0 supported Ruby 1.8.6, with JRuby 1.4.0 updating that compatibility to Ruby 1.8.7. JRuby 1.6.0 added simultaneous support for Ruby 1.9.2, with JRuby 1.7.0 making Ruby 1.9.3 the default execution mode (Ruby 1.8.7 compatibility is available via a command-line flag). JRuby 9.0.0.0 added support for Ruby 2.2.

The current version of JRuby (9.4.3.0) targets Ruby 3.1, though some 3.1 features are still in work.{{cite web | url=https://github.com/jruby/jruby/issues/7460 | title=Unfinished Ruby 3.1 features | publisher=JRuby Team | access-date=June 13, 2023}}

Ruby on Rails

JRuby has been able to run the Ruby on Rails web framework since version 0.9 (May 2006),{{cite web | url=http://wiki.jruby.org/wiki/Rails_Support | title=Rails Support | publisher=JRuby Team | access-date=February 17, 2008 | archive-date=March 3, 2008 | archive-url=https://web.archive.org/web/20080303021232/http://wiki.jruby.org/wiki/Rails_Support | url-status=dead | url=http://blog.headius.com/2008/08/zero-to-production-in-15-minutes.html | title=Zero to Production in 15 Minutes | last=Nutter|first=Charles | date=August 24, 2008 | access-date=August 27, 2008}} with the ability to execute RubyGems and WEBrick. Since the hiring of the two lead developers by Sun, Rails compatibility and speed have improved greatly. JRuby version 1.0 successfully passed nearly all of Rails's own test cases. Since then, developers have begun to use JRuby for Rails applications in production environments.{{cite web | url=https://github.com/jruby/jruby/wiki/SuccessStories | title=Success Stories | publisher=JRuby Wiki on GitHub | date=January 5, 2011 | access-date=March 16, 2011}}

Multiple virtual machine collaboration

On February 27, 2008, Sun Microsystems and the University of Tokyo announced a joint-research project to implement a virtual machine capable of executing more than one Ruby or JRuby application on one interpreter.{{cite web | url=http://www.sun.com/aboutsun/pr/2008-02/sunflash.20080227.5.xml | title=The University of Tokyo and Sun Microsystems Commence Joint Research Projects on High Performance Computing and Web-based Programming Languages | publisher=Sun Microsystems | date=February 27, 2008 | access-date=February 28, 2008}}

Dynamic invocation on Java Virtual Machines

JSR 292 (Supporting Dynamically Typed Languages on the JavaTM Platform) proposes:

  • adding a new invokedynamic instruction at the JVM level, allowing method invocation using dynamic type checking,
  • dynamically changing classes and methods at runtime.

The Sun Open source project Multi Language Virtual Machine aims to prototype this JSR.{{cite web | url=http://openjdk.java.net/projects/mlvm/subprojects.html | title=Sub-Projects and Investigations | year=2007 |publisher=Sun Microsystems | access-date=February 6, 2008}} The first working prototype, developed as a patch on OpenJDK, was announced and made available on end of August 2008.{{cite web | url=https://blogs.oracle.com/jrose/entry/international_invokedynamic_day | date=August 26, 2008 | title=Happy International Invokedynamic Day! | last=Rose|first=John | access-date=September 3, 2008}}{{cite web | url=http://www.infoq.com/news/2008/09/invokedynamic_day | title=Dynamic Invocation Runs on OpenJDK | last=Lorimer|first=R.J. | publisher=infoq.com | date=September 1, 2008 | access-date=September 3, 2008}}

The JRuby team has implemented dynamic invocation into their codebase. Dynamic invocation initially shipped with the 1.1.5 release in a primitive form.{{cite web | url=http://blog.headius.com/2008/09/first-taste-of-invokedynamic.html | title=A First Taste of InvokeDynamic | last=Nutter|first=Charles | quote=I managed to successfully wire InvokeDynamic directly into JRuby's dispatch process! Such excitement! The code is already in JRuby's trunk, and will ship with JRuby 1.1.5 (though it obviously will be disabled on JVMs without InvokeDynamic). | date=September 11, 2008 | access-date=September 13, 2008}} Version 1.7.0 enabled it by default on Java 8 builds.{{cite web | url=http://jruby.org/2012/10/22/jruby-1-7-0.html | title=JRuby 1.7.0 Released | publisher=JRuby Team | date=October 22, 2012 | access-date=October 23, 2011 | archive-date=October 25, 2012 | archive-url=https://web.archive.org/web/20121025001231/http://www.jruby.org/2012/10/22/jruby-1-7-0.html | url-status=dead

Release history

This table presents only releases that present significant steps in JRuby history, aside from versions that mainly fixed bugs and improved performance. Performance improvements are also not shown in the table below, as every release has usually brought such improvements. ::data[format=table]

ReleaseRelease dateHighlights
0.9August 1, 2006Rails support
1.1March 28, 2008AOT mode]] and JIT mode
1.1.4August 28, 2008Refactored Java integration layer
Beginning of Ruby 1.9 support
FFI subsystem for calling C libraries{{cite web
1.2.0{{cite weburl = http://docs.codehaus.org/display/JRUBY/2009/03/16/JRuby+1.2.0+Releasedtitle = JRuby 1.2.0 Released
1.3.0{{cite weburl = http://docs.codehaus.org/display/JRUBY/2009/06/03/JRuby+1.3.0+Releasedtitle = JRuby 1.3.0 Released
1.4.0{{cite weburl=http://www.jruby.org/2009/11/02/jruby-1-4-0title=JRuby 1.4.0 Released
1.5.0{{cite weburl=http://jruby.org/2010/05/12/jruby-1-5-0title=JRuby 1.5.0 Released
1.6.0{{cite weburl=http://www.jruby.org/2011/03/15/jruby-1-6-0.htmltitle=JRuby 1.6.0 Released
1.7.0October 22, 2012
Support for invokedynamic
1.7.4{{cite weburl=http://www.jruby.org/2013/05/16/jruby-1-7-4.htmltitle=JRuby 1.7.4 Released
9.0.0.0{{cite weburl=http://jruby.org/2015/07/22/jruby-9-0-0-0.htmltitle=JRuby 9.0.0.0 Released
9.1.7.0January 11, 2017Fixed serious LinkageError when using multiple threads
9.2.0.0May 24, 2018
9.2.9.0October 30, 2019
9.3.2.0December 2, 2021
9.3.3.0January 19, 2022
9.3.4.0March 23, 2022
9.4.0.0November 22, 2022
9.4.1.0February 7, 2023
9.4.2.0March 8, 2023
9.4.3.0June 7, 2023
::

Design

Since early 2006, the current JRuby core team has endeavored to move JRuby beyond being a simple C port, to support better performance and to aid eventual compilation to Java bytecode. To support this end, the team set an ambitious goal: to be able to run Ruby on Rails unmodified using JRuby. In the process of achieving this goal, the JRuby test suite expanded to such extent that the team gained confidence in the "correctness" of JRuby. As a result, toward the end of 2006 and in the beginning of 2007, they began to commit much more complicated redesigns and refactorings of JRuby's core subsystems.

JRuby is designed to work as a mixed-mode virtual machine for Ruby, where code can be either interpreted directly, just-in-time compiled at runtime to Java bytecode, or ahead-of-time compiled to Java bytecode before execution. Until October 2007, only the interpreted mode supported all Ruby's constructs, but a full AOT/JIT compiler is available since version 1.1.{{cite web | url=https://headius.blogspot.com/2007/09/compiler-is-complete.html | title=The Compiler Is Complete | date=September 27, 2007 |last=Nutter|first=Charles | access-date=October 12, 2007}} The compiler design allows for interpreted and compiled code to run side-by-side, as well as decompilation to reoptimize and outputting generated bytecode as Java class files.

Frameworks support

JRuby has built-in support for Rails, RSpec, Rake, and RubyGems. It embeds an FFI subsystem to allow the use of C libraries bundled as gems. It also allows launching the Interactive Ruby Shell (irb) as Ruby MRI does.

The Netbeans Ruby Pack, available in NetBeans 6, allows IDE development with Ruby and JRuby, as well as Ruby on Rails for the two implementations of Ruby.{{cite web | url=http://www.netbeans.org/servlets/NewsItemView?newsItemID=1015 | title=Ruby & JRuby Support Available in NetBeans IDE | date=March 6, 2007 | publisher=netbeans.org | access-date=July 4, 2009 | archive-date=July 19, 2011 | archive-url=https://web.archive.org/web/20110719115409/http://netbeans.org/servlets/NewsItemView?newsItemID=1015 | url-status=dead | url=http://www.infoworld.com/d/developer-world/ruby-brightens-netbeans-platform-390 | title=Ruby brightens the NetBeans platform | date=March 1, 2007 | publisher=infoworld.com | access-date=July 4, 2008}} It is no longer included in NetBeans 7.0 and later.

Programming

Ruby meets Java

JRuby is similar to the standard Ruby interpreter except written in Java. JRuby features some of the same concepts, including object-oriented programming, and dynamic typing as Ruby. The key difference is that JRuby is tightly integrated with Java, and can be called directly from Java programs.{{cite web |last1=Fox |first1=Joshua |date=July 17, 2006 |df=mdy |url=https://www.infoworld.com/article/2071794/ruby-for-the-java-world.html |title=Ruby for the Java world |work=JavaWorld |access-date=July 26, 2020

JRuby calling Java

One powerful feature of JRuby is its ability to invoke the classes of the Java Platform. To do this, one must first load JRuby's Java support, by calling "require 'java'". The following example creates a Java JFrame with a JLabel: ::code[lang=ruby] require 'java'

frame = javax.swing.JFrame.new frame.getContentPane.add javax.swing.JLabel.new('Hello, World!') frame.setDefaultCloseOperation javax.swing.JFrame::EXIT_ON_CLOSE frame.pack frame.set_visible true ::

JRuby also allows the user to call Java code using the more Ruby-like underscore method naming and to refer to JavaBean properties as attributes: ::code[lang=ruby] frame.content_pane.add label frame.visible = true ::

Calling JRuby from Java

JRuby can just as easily be called from Java, using either the JSR 223 Scripting for Java 6 or the Apache Bean Scripting framework.

::code[lang='java'] //Example using JSR 233 Scripting for Java 6 ScriptEngineManager mgr = new ScriptEngineManager(); ScriptEngine rbEngine = mgr.getEngineByExtension("rb"); try { rbEngine.eval("puts 'Hello World!'"); } catch (ScriptException ex) { ex.printStackTrace(); }
::

Performance

According to some benchmarks, JRuby is faster than alternatives. Since implementations vary in how much code is loaded before execution, different methods of measuring speed can lead to biased interpretations of performance advantages. The time it takes for a Java Virtual Machine itself to load is often excluded from execution times when calculating benchmarks.

JRuby has the significant architectural advantage to be able to leverage JVM threads without being constrained by a global interpreter lock (similarly to Rubinius), therefore achieving full parallelism within a process, which Ruby MRI cannot achieve despite leveraging OS threads.

In a real Mongrel web server application tested in 2007, JRuby performance is better than Ruby MRI 1.8, after the Java Virtual Machine had been instantiated.{{cite web | url=http://blog.nicksieger.com/articles/2007/10/25/jruby-on-rails-fast-enough | title=JRuby on Rails: Fast Enough | date=October 25, 2007 |last=Sieger|first=Nick | access-date=October 28, 2007}}

In a 2007 benchmark of Ruby implementations, JRuby was faster than Ruby MRI 1.8 in some tests, but YARV outperformed both of them.{{cite web | url=http://programmingzen.com/2007/12/03/the-great-ruby-shootout/ | title=The Great Ruby Shootout | date=December 3, 2007 | last=Cangiano|first=Antonio | access-date=February 2, 2014}}

As of April 2014, in The Computer Language Benchmarks Game, JRuby 1.7.4 typically has the same performance as Ruby MRI 2.1.0, but uses more memory. | url=http://benchmarksgame.alioth.debian.org/u64q/jruby.html | title=JRuby compared to Ruby 1.9, Computer Language Benchmarks Game (1) | access-date=February 2, 2014 | archive-url=https://web.archive.org/web/20150123023501/http://benchmarksgame.alioth.debian.org/u64q/jruby.html | archive-date=January 23, 2015 | url-status=dead |url = http://benchmarksgame.alioth.debian.org/u64/jruby.php |title = JRuby compared to Ruby 1.9, Computer Language Benchmarks Game (2) |access-date = February 2, 2014 |archive-url = https://web.archive.org/web/20140723042024/http://benchmarksgame.alioth.debian.org/u64/jruby.php |archive-date = July 23, 2014 |url-status = dead

References

References

  1. Jacki. (September 7, 2006). "Sun Welcomes JRuby Developers". On the Record.
  2. Ola Bini. (2007). "ThoughtWorks". On the Record.
  3. (July 28, 2009). "Sun's JRuby Team Jumps Ship to Engine Yard".
  4. (May 23, 2012). "Red Hat lures in JRuby power pair".
  5. Nutter, Charles. (July 28, 2009). "JRuby's Future at Engine Yard".
  6. 98.6% of the 2,807 Rails-specific test cases execute successfully; see [http://docs.codehaus.org/display/JRUBY/2007/03/05/JRuby+0.9.8+Released JRuby 0.9.8 Released] {{webarchive. link. (May 22, 2015)
  7. [https://www.jcp.org/en/jsr/detail?id=292 see JSR 292]
  8. "JRuby 9.1.7.0 Released — JRuby.org".
  9. "JRuby 9.2.0.0 Released".
  10. "JRuby 9.2.9.0 Released".
  11. "JRuby 9.3.2.0 Released".
  12. "JRuby 9.3.3.0 Released".
  13. "JRuby 9.3.4.0 Released".
  14. "JRuby 9.4.0.0 Released".
  15. "JRuby 9.4.1.0 Released".
  16. "JRuby 9.4.2.0 Released".
  17. "JRuby 9.4.3.0 Released".
  18. Eyler, Pat. (17 July 2006). "Interviewing the JRuby Developers -".
  19. [http://jcp.org/aboutJava/communityprocess/final/jsr223/index.html JSR 223: Scripting for the Java Platform Specification Request]

::callout[type=info title="Wikipedia Source"] This article was imported from Wikipedia and is available under the Creative Commons Attribution-ShareAlike 4.0 License. Content has been adapted to SurfDoc format. Original contributors can be found on the article history page. ::

free-software-programmed-in-javafree-software-programmed-in-rubyjvm-programming-languagesobject-oriented-programming-languagesruby-(programming-language)scripting-languagessoftware-using-the-eclipse-public-license