[[Home|» JRuby Project Wiki Home Page]]
a-bJRuby has long had a private embedding API, which was closely tied to the runtime's internals and therefore changed frequently as JRuby evolved. Since version 1.4, however, we have also provided a more stable public API, known as Red Bridge or JRuby Embed. Existing Java programs written to the [[DirectJRubyEmbedding|legacy API]] should still work, but we strongly recommend Red Bridge for all new projects. == Features of Red Bridge == Red Bridge consists of two layers: Embed Core on the bottom, and implementations of [http://www.jcp.org/en/jsr/detail?id=223 JSR223] and [http://jakarta.apache.org/bsf/ BSF] on top. Embed Core is JRuby-specific, and can take advantage of much of JRuby's power. JSR223 and BSF are more general interfaces that provide a common ground across scripting languages. Which API should you use? For projects where Ruby is the only scripting language involved, we recommend Embed Core for the following reasons: # With Embed Core, you can create several Ruby environments in one JVM, and configure them individually (via
org.jruby.RubyInstanceConfig
. With the other APIs, configuration options can only be set globally, via the System
properties.
# Embed Core offers several shortcuts, such as loading scripts from a java.io.InputStream
, or returning Java-friendly objects from Ruby code. These allow you to skip a lot of boilerplate.
For projects requiring multiple scripting languages, JSR223 is a good fit. Though the API is language-independent, JRuby's implementation of it allows you to set some Ruby-specific options. In particular, you can control the threading model of the scripting engine, the lifetime of local variables, compilation mode, and how line numbers are displayed.
The full [http://jruby-embed.kenai.com/docs/ API documentation] has all the gory details. It's worth talking about a couple of the finer points here.
= Previous Embedding JRuby Page=
We recommend using Embed Core; however, if you're maintaining code that uses the old API, you can find its documentation on the [[JavaIntegration|legacy embedding]]This link goes nowhere. page.
= References =