# Ruby and legacy Java Applications

**URL:** <https://www.ruby-forum.com/t/ruby-and-legacy-java-applications/154773>\
**Category:** Ruby\
**Created:** [December 3, 2008, 7:44pm UTC](https://www.ruby-forum.com/t/ruby-and-legacy-java-applications/154773 "2008-12-03T19:44:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joe\_WSSSSlfel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@Joe\_WSSSSlfel](https://www.ruby-forum.com/u/Joe_WSSSSlfel)\
**Post date:** [December 3, 2008, 7:44pm UTC](https://www.ruby-forum.com/t/ruby-and-legacy-java-applications/154773/1 "2008-12-03T19:44:14Z")

</div>

What are some good ways to integrate Ruby into legacy Java  
applications? I realize  
I can execute small Ruby scripts from Java like this:

```
     Ruby runtime = Ruby.newInstance();
     runtime.evalScriptlet("puts 'Hello from Ruby'");

```

However, this seems to lend itself only to small snippets of Ruby.  
Often I’m more likely  
to have a larger body of Ruby code that includes many files, gem  
dependencies, and  
the ability to work with legacy installers. Is there an easy way to  
accomplish this?

---

<div class="post-metadata">

**Author:** ![Joe\_WSSSSlfel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@Joe\_WSSSSlfel](https://www.ruby-forum.com/u/Joe_WSSSSlfel)\
**Post date:** [December 3, 2008, 11:22pm UTC](https://www.ruby-forum.com/t/ruby-and-legacy-java-applications/154773/2 "2008-12-03T23:22:47Z")

</div>

Joe WÃ¶lfel wrote:

> What are some good ways to integrate Ruby into legacy Java  
> applications? I realize  
> I can execute small Ruby scripts from Java like this:
> 
> ```
> Ruby runtime = Ruby.newInstance();
> runtime.evalScriptlet("puts 'Hello from Ruby'");
> 
> ```
> 
> However, this seems to lend itself only to small snippets of Ruby.  
> Often I’m more likely  
> to have a larger body of Ruby code that includes many files, gem  
> dependencies, and  
> the ability to work with legacy installers. Is there an easy way to  
> accomplish this?

Try the free tool TudbcJRubyServlet  
[http://www.tudbc.org/tudbcjrubyservlet](http://www.tudbc.org/tudbcjrubyservlet)  
which allows you to use JRuby (which is compatible with Ruby 1.8.6) in a  
Java EE (such as GlassFish, Resin, Tomcat, etc), which automatically  
will allow you to use your Java codes.

---

<div class="post-metadata">

**Author:** ![Joe\_WSSSSlfel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@Joe\_WSSSSlfel](https://www.ruby-forum.com/u/Joe_WSSSSlfel)\
**Post date:** [December 4, 2008, 8:34pm UTC](https://www.ruby-forum.com/t/ruby-and-legacy-java-applications/154773/3 "2008-12-04T20:34:26Z")

</div>

Joe WÃ¶lfel wrote:

> dependencies, and  
> the ability to work with legacy installers. Is there an easy way to  
> accomplish this?

In general the easiest way would be to have the Ruby code implement a  
Java interface and get that instance back into Java. There’s a few  
examples on [wiki.jruby.org](http://wiki.jruby.org). Does that sound lke what you want?

- Charlie

---

<div class="post-metadata">

**Author:** ![Joe\_WSSSSlfel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@Joe\_WSSSSlfel](https://www.ruby-forum.com/u/Joe_WSSSSlfel)\
**Post date:** [December 5, 2008, 3:44am UTC](https://www.ruby-forum.com/t/ruby-and-legacy-java-applications/154773/4 "2008-12-05T03:44:31Z")

</div>

Richard C. wrote:

> to gain access to easy JIRB debugging.  
> Yup, ought to work just fine. I suppose it only depends on whether you  
> control the entry point or not. If you’re adding Ruby to an existing  
> Java application, you don’t necessarily have that option. But writing it  
> in Ruby to start, just calling out to Java as needed, is certainly a  
> simpler way.

- Charlie

---

<div class="post-metadata">

**Author:** ![Joe\_WSSSSlfel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@Joe\_WSSSSlfel](https://www.ruby-forum.com/u/Joe_WSSSSlfel)\
**Post date:** [December 5, 2008, 12:13am UTC](https://www.ruby-forum.com/t/ruby-and-legacy-java-applications/154773/5 "2008-12-05T00:13:15Z")

</div>

On Thu, Dec 4, 2008 at 7:28 PM, Charles Oliver N.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > I’m more likely  
> > to have a larger body of Ruby code that includes many files, gem  
> > dependencies, and  
> > the ability to work with legacy installers. Is there an easy way to  
> > accomplish this?
> 
> In general the easiest way would be to have the Ruby code implement a Java  
> interface and get that instance back into Java. There’s a few examples on  
> [wiki.jruby.org](http://wiki.jruby.org). Does that sound lke what you want?

I am just curious, but couldn’t you also have a JRuby script construct  
and execute  
your application’s mainline? Or duplicate the behaviour of the  
mainline in some way.

That way you can extend Java functionality with Ruby, because you have  
wrapped  
your entire app up in Ruby to begin with.

I have to admit that this is something I have been thinking about for  
a while, if only  
to gain access to easy JIRB debugging.
