# Calling a Java Class

**URL:** <https://rubytalk.org/t/calling-a-java-class/32111>\
**Category:** ruby-talk\
**Created:** [20 October 2006 00:20 UTC](https://rubytalk.org/t/calling-a-java-class/32111 "2006-10-20T00:20:14Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ike](https://avatars.discourse-cdn.com/v4/letter/i/df705f/32.png) [@Ike](https://rubytalk.org/u/Ike)\
**Post date:** [20 October 2006 00:20 UTC](https://rubytalk.org/t/calling-a-java-class/32111/1 "2006-10-20T00:20:14Z")

</div>

Is there a way to invoke a Java class, from within Ruby, without using, say  
JRuby? I am looking at getting very involved in JRuby, but just want to  
check if there isn;t some alternative means within Ruby itself for doing  
this.

Thanks, Ike

---

<div class="post-metadata">

**Author:** ![snacktime](https://avatars.discourse-cdn.com/v4/letter/s/7feea3/32.png) [@snacktime](https://rubytalk.org/u/snacktime)\
**Post date:** [20 October 2006 00:34 UTC](https://rubytalk.org/t/calling-a-java-class/32111/2 "2006-10-20T00:34:17Z")

</div>

I believe there are one or two jni libraries for ruby, but I've never  
really looked into them.

> **···**
>
> On 10/19/06, Ike \<rxv@hotmail.com\> wrote:
> 
> > Is there a way to invoke a Java class, from within Ruby, without using, say  
> > JRuby? I am looking at getting very involved in JRuby, but just want to  
> > check if there isn;t some alternative means within Ruby itself for doing  
> > this.
> > 
> > Thanks, Ike

---

<div class="post-metadata">

**Author:** ![David\_Vallner](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@David\_Vallner](https://rubytalk.org/u/David_Vallner)\
**Post date:** [20 October 2006 00:55 UTC](https://rubytalk.org/t/calling-a-java-class/32111/3 "2006-10-20T00:55:48Z")

</div>

Ike wrote:

> Is there a way to invoke a Java class, from within Ruby, without using, say  
> JRuby?

[http://rjb.rubyforge.org/](http://rjb.rubyforge.org/) for one. Never used it, seems active -ish though.

David Vallner

---

<div class="post-metadata">

**Author:** ![Jared\_Richardson1](https://avatars.discourse-cdn.com/v4/letter/j/46a35a/32.png) [@Jared\_Richardson1](https://rubytalk.org/u/Jared_Richardson1)\
**Post date:** [20 October 2006 03:30 UTC](https://rubytalk.org/t/calling-a-java-class/32111/4 "2006-10-20T03:30:11Z")

</div>

If you'll forgive me posting my own blog entry

[http://www.jaredrichardson.net/blog/2006/09/01/#yajb](http://www.jaredrichardson.net/blog/2006/09/01/#yajb)

It sounds like you need to look at the Ruby Bridge project  
([http://rjb.rubyforge.org/\](http://rjb.rubyforge.org/%5C)) and the Yet Another Java Bridge project  
([Software Error](http://www.cmt.phys.kyushu-u.ac.jp/~M.Sakurai/cgi-bin/fw/wiki.cgi?page=YAJB%5C)).

Jared  
[http://jaredrichardson.net](http://jaredrichardson.net)

> **···**
>
> --
> 
> "Ike" \<rxv@hotmail.com\> wrote in message  
> news:TzUZg.11721$Y24.7667@newsread4.news.pas.earthlink.net...
> 
> > Is there a way to invoke a Java class, from within Ruby, without using,  
> > say JRuby? I am looking at getting very involved in JRuby, but just want  
> > to check if there isn;t some alternative means within Ruby itself for  
> > doing this.
> > 
> > Thanks, Ike

---

<div class="post-metadata">

**Author:** ![Zouplaz](https://avatars.discourse-cdn.com/v4/letter/z/a4c791/32.png) [@Zouplaz](https://rubytalk.org/u/Zouplaz)\
**Post date:** [20 October 2006 09:50 UTC](https://rubytalk.org/t/calling-a-java-class/32111/5 "2006-10-20T09:50:08Z")

</div>

You could use xml-rpc or something similar to call a java process from a ruby process...

You have to embbed your class in a java server, like Jetty (which is pretty lightweighted)

It's a good solution if your project is big enough (is worth the added work)

> **···**
>
> le 20/10/2006 02:16, Ike nous a dit:
> 
> > Is there a way to invoke a Java class, from within Ruby, without using, say JRuby? I am looking at getting very involved in JRuby, but just want to check if there isn;t some alternative means within Ruby itself for doing this.

---

<div class="post-metadata">

**Author:** ![Ike](https://avatars.discourse-cdn.com/v4/letter/i/df705f/32.png) [@Ike](https://rubytalk.org/u/Ike)\
**Post date:** [20 October 2006 14:20 UTC](https://rubytalk.org/t/calling-a-java-class/32111/6 "2006-10-20T14:20:14Z")

</div>

yeah....YAJB seems to be exactly what I am looking for. Any reason you know  
if that it canot be run in Rails?

-Ike

---

<div class="post-metadata">

**Author:** ![Charles\_Oliver\_Nutt1](https://avatars.discourse-cdn.com/v4/letter/c/5f9b8f/32.png) [@Charles\_Oliver\_Nutt1](https://rubytalk.org/u/Charles_Oliver_Nutt1)\
**Post date:** [21 October 2006 15:23 UTC](https://rubytalk.org/t/calling-a-java-class/32111/7 "2006-10-21T15:23:43Z")

</div>

Zouplaz wrote:

> You could use xml-rpc or something similar to call a java process from a ruby process...
> 
> You have to embbed your class in a java server, like Jetty (which is pretty lightweighted)
> 
> It's a good solution if your project is big enough (is worth the added work)

Of course I need to chime in and say that although there are other options, calling a Java class is trivially easy in JRuby, so if it's simplicity you're looking for it might be the best way to go. Other options are great if you have the restriction of running only under the C implementation, but for straight Ruby-to-Java calling JRuby is the cleanest and simplest option.

> **···**
>
> --  
> Charles Oliver Nutter, JRuby Core Developer  
> headius@headius.com -- charles.o.nutter@sun.com  
> Blogging at headius.blogspot.com

---

<div class="post-metadata">

**Author:** ![Murray\_Steele1](https://avatars.discourse-cdn.com/v4/letter/m/cdc98d/32.png) [@Murray\_Steele1](https://rubytalk.org/u/Murray_Steele1)\
**Post date:** [20 October 2006 14:44 UTC](https://rubytalk.org/t/calling-a-java-class/32111/8 "2006-10-20T14:44:38Z")

</div>

I've used YAJB to power some PDF generation stuff using Apache FOP in a  
rails app. Can't say I've noticed any problems, but then the app's not  
exactly in high-load usage, so take what I say with a healthy pinch of salt.

> **···**
>
> On 20/10/06, Ike \<rxv@hotmail.com\> wrote:
> 
> > yeah....YAJB seems to be exactly what I am looking for. Any reason you  
> > know  
> > if that it canot be run in Rails?
> > 
> > -Ike

---

<div class="post-metadata">

**Author:** ![Ike](https://avatars.discourse-cdn.com/v4/letter/i/df705f/32.png) [@Ike](https://rubytalk.org/u/Ike)\
**Post date:** [22 October 2006 02:20 UTC](https://rubytalk.org/t/calling-a-java-class/32111/9 "2006-10-22T02:20:16Z")

</div>

I have to add that JRuby 0.9.1 is just amazing. This truly melds the best of  
both worlds, and you guys on the JRuby team have done incredible work on  
this important piece of software.

---

<div class="post-metadata">

**Author:** ![Charles\_Oliver\_Nutt1](https://avatars.discourse-cdn.com/v4/letter/c/5f9b8f/32.png) [@Charles\_Oliver\_Nutt1](https://rubytalk.org/u/Charles_Oliver_Nutt1)\
**Post date:** [22 October 2006 08:27 UTC](https://rubytalk.org/t/calling-a-java-class/32111/10 "2006-10-22T08:27:05Z")

</div>

Ike wrote:

> I have to add that JRuby 0.9.1 is just amazing. This truly melds the best of both worlds, and you guys on the JRuby team have done incredible work on this important piece of software.

Cool, thanks 🙂 And I'm sure all the previous contributors to JRuby thank you as well.

> **···**
>
> --  
> Charles Oliver Nutter, JRuby Core Developer  
> headius@headius.com -- charles.o.nutter@sun.com  
> Blogging at headius.blogspot.com

---

<div class="post-metadata">

**Author:** ![David\_Vallner](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@David\_Vallner](https://rubytalk.org/u/David_Vallner)\
**Post date:** [23 October 2006 00:40 UTC](https://rubytalk.org/t/calling-a-java-class/32111/11 "2006-10-23T00:40:54Z")

</div>

Charles Oliver Nutter wrote:

> Ike wrote:
> 
> > I have to add that JRuby 0.9.1 is just amazing. This truly melds the  
> > best of both worlds, and you guys on the JRuby team have done  
> > incredible work on this important piece of software.
> 
> Cool, thanks 🙂 And I'm sure all the previous contributors to JRuby  
> thank you as well.

Any odds the Groovy JSR gets dragged out and shot^W^W^W^W displaced by a  
JRuby one? Without aiming to bash Groovy (more), I'd much prefer JRuby  
for doing (Cruel and) unusual things onna JVM using DSLs instead of  
first-class feature creep.

(Even if, aside from Weird Things, I follow the Beanshell Whenever  
Possible policy for impedance mismatch minimisation reasons.)

Speaking of Weird Things, IntelliJ IDEA plugin anyone? Inspecting beans  
during a debugger breakpoint using JRuby has a certain ring to it.  
Spawning a REPL with module / project classes loaded more so. I've been  
pondering getting myself a pet project of General Usefulness to toy  
with, except I have no idea where I'd start with this sort of hackery  
which involves touching the JVM in all the wrong places.

David Vallner
