# JRuby

**URL:** <https://rubytalk.org/t/jruby/3533>\
**Category:** ruby-talk\
**Created:** [11 December 2002 17:05 UTC](https://rubytalk.org/t/jruby/3533 "2002-12-11T17:05:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shannon\_Fang](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@Shannon\_Fang](https://rubytalk.org/u/Shannon_Fang)\
**Post date:** [11 December 2002 17:05 UTC](https://rubytalk.org/t/jruby/3533/1 "2002-12-11T17:05:37Z")

</div>

Hi,

I am learning to use JRuby. Currently just started reading the documents.  
From a glimpse, I got an impression that JRuby enables you to use java  
classes in your ruby program. However, I am more interested in how to use  
ruby script in java applications, because it is easier to adopt ruby in Java  
environment (for commercial purpose) rather than vice versa.

Although the document mentioned that JRuby enables you to embed a ruby  
interpreter into your java application, I have not seen any document or  
samples on this. Could any one give me a hint? Preferrably several line of  
code to get a look and fee.

Thanks a lot!

Shannon

> **···**
>
> * * *
> 
> STOP MORE SPAM with the new MSN 8 and get 2 months FREE\*  
> [http://join.msn.com/?page=features/junkmail](http://join.msn.com/?page=features/junkmail)

---

<div class="post-metadata">

**Author:** ![Anders\_Bengtsson](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@Anders\_Bengtsson](https://rubytalk.org/u/Anders_Bengtsson)\
**Post date:** [12 December 2002 20:11 UTC](https://rubytalk.org/t/jruby/3533/2 "2002-12-12T20:11:02Z")

</div>

Shannon Fang wrote:

> Although the document mentioned that JRuby enables you to embed a ruby  
> interpreter into your java application, I have not seen any document or  
> samples on this. Could any one give me a hint? Preferrably several line of  
> code to get a look and fee.

Hi Shannon,

We’re a little short on documentation in some areas on JRuby. But it’s  
pretty easy to embed the JRuby interpreter. Something like this (beware,  
untested):

Ruby runtime = org.jruby.Ruby.getDefaultInstance();  
runtime.evalScript(“puts 1 + 2”);

That’s about it. You can also pass in a stream of Ruby source instead,  
to evaluate bigger scripts. The docs on JRuby’s Java support should be  
able to help you with the rest.

You may be able to find someone with some more interesting sample code  
on the jruby-user mailing list.  
By the way, we would be grateful if someone gave us a good sample  
application that embeds JRuby to distribute with our sample code.

/Anders - your friendly neighborhood JRuby developer

> **···**
>
> –
> 
> A n d e r s B e n g t s s o n | ndrsbngtssn@yahoo.se  
> Stockholm, Sweden |
> 
> * * *
> 
> Gratis e-mail resten av livet på www.yahoo.se/mail  
> Busenkelt!

---

<div class="post-metadata">

**Author:** ![Shannon\_Fang](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@Shannon\_Fang](https://rubytalk.org/u/Shannon_Fang)\
**Post date:** [12 December 2002 21:06 UTC](https://rubytalk.org/t/jruby/3533/3 "2002-12-12T21:06:26Z")

</div>

Hi Anders,

Thanks. I will let you know my test result on JRuby. BTW, I’m also very  
interested in your effort of trying to compile ruby into Java Byte Code.  
Is it under development now? And how about compile Ruby into Java SOURCE  
code?

I look forward to see greate success of JRuby, and Ruby itself. I do  
hope that Ruby is widely accepted in commercial environment. It can  
drastically improve efficiency and produce bug-less and easy  
maintainable code…

Shannon

> **···**
>
> On Fri, 13 Dec 2002 05:11:02 +0900 Anders Bengtsson [ndrsbngtssn@yahoo.se](mailto:ndrsbngtssn@yahoo.se) wrote:
> 
> > Shannon Fang wrote:
> > 
> > > Although the document mentioned that JRuby enables you to embed a ruby  
> > > interpreter into your java application, I have not seen any document or  
> > > samples on this. Could any one give me a hint? Preferrably several line of  
> > > code to get a look and fee.
> > 
> > Hi Shannon,
> > 
> > We’re a little short on documentation in some areas on JRuby. But it’s  
> > pretty easy to embed the JRuby interpreter. Something like this (beware,  
> > untested):
> > 
> > Ruby runtime = org.jruby.Ruby.getDefaultInstance();  
> > runtime.evalScript(“puts 1 + 2”);
> > 
> > That’s about it. You can also pass in a stream of Ruby source instead,  
> > to evaluate bigger scripts. The docs on JRuby’s Java support should be  
> > able to help you with the rest.
> > 
> > You may be able to find someone with some more interesting sample code  
> > on the jruby-user mailing list.  
> > By the way, we would be grateful if someone gave us a good sample  
> > application that embeds JRuby to distribute with our sample code.
> > 
> > /Anders - your friendly neighborhood JRuby developer
> > 
> > –
> > 
> > A n d e r s B e n g t s s o n | ndrsbngtssn@yahoo.se  
> > Stockholm, Sweden |
> > 
> > * * *
> > 
> > Gratis e-mail resten av livet p~{e ~}www.yahoo.se/mail  
> > Busenkelt!

---

<div class="post-metadata">

**Author:** ![Anders\_Bengtsson](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@Anders\_Bengtsson](https://rubytalk.org/u/Anders_Bengtsson)\
**Post date:** [14 December 2002 01:46 UTC](https://rubytalk.org/t/jruby/3533/4 "2002-12-14T01:46:50Z")

</div>

Shannon Fang wrote:

> Thanks. I will let you know my test result on JRuby. BTW, I’m also very  
> interested in your effort of trying to compile ruby into Java Byte Code.  
> Is it under development now? And how about compile Ruby into Java SOURCE  
> code?

I’ve started on the compiler, but so far it can only compile a few  
statements. There are other areas in JRuby that needs more attention, so  
more work on the compiler may have to wait.  
Compiling into Java source code is a little easier than generating  
bytecode, but also a little less practical. It could probably be done  
using much of the same code as the bytecode compiler.

/Anders

> **···**
>
> –
> 
> A n d e r s B e n g t s s o n | ndrsbngtssn@yahoo.se  
> Stockholm, Sweden |
> 
> * * *
> 
> Följ VM på nära håll på Yahoo!s officielle VM-sajt www.yahoo.se/vm2002  
> Håll dig ajour med nyheter och resultat, med vinnare och förlorare…

---

<div class="post-metadata">

**Author:** ![Shannon\_Fang](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@Shannon\_Fang](https://rubytalk.org/u/Shannon_Fang)\
**Post date:** [14 December 2002 02:21 UTC](https://rubytalk.org/t/jruby/3533/5 "2002-12-14T02:21:23Z")

</div>

Hi,

> Compiling into Java source code is a little easier than generating  
> bytecode, but also a little less practical. It could probably be done  
> using much of the same code as the bytecode compiler.

I think compiling into java source code is very useful, simply for  
political reason. If I can convert Ruby code into Java source, I can  
easily impress my boss about the speed that I can program in Java. It is  
so significant that I think it will make Ruby easily acceptable for  
business usage. While Ruby is more mature (for example, Rite?) no body  
need to convert Ruby into Java again.

What do you think?

Shannon

> **···**
>
> On Sat, 14 Dec 2002 10:46:50 +0900 Anders Bengtsson [ndrsbngtssn@yahoo.se](mailto:ndrsbngtssn@yahoo.se) wrote:

---

<div class="post-metadata">

**Author:** ![Michael\_Campbell1](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@Michael\_Campbell1](https://rubytalk.org/u/Michael_Campbell1)\
**Post date:** [14 December 2002 03:40 UTC](https://rubytalk.org/t/jruby/3533/6 "2002-12-14T03:40:59Z")

</div>

> I think compiling into java source code is very useful, simply for  
> political reason. If I can convert Ruby code into Java source, I can  
> easily impress my boss about the speed that I can program in Java. It is  
> so significant that I think it will make Ruby easily acceptable for  
> business usage. While Ruby is more mature (for example, Rite?) no body  
> need to convert Ruby into Java again.
> 
> What do you think?

I think if your boss saw the java code that _ANY_ ‘cross language’ converter  
spit out, he’d forbid you from ever using it.

It’s one thing to be able to turn ruby into java, it’s another thing entirely  
from being able to maintain that java code later. And if you can’t ever  
maintain it, you have to go to the source, which is ruby. From his point of  
view, that’s no different than not having this java intermediary to begin with.

---

<div class="post-metadata">

**Author:** ![Bulat\_Ziganshin](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Bulat\_Ziganshin](https://rubytalk.org/u/Bulat_Ziganshin)\
**Post date:** [15 December 2002 06:21 UTC](https://rubytalk.org/t/jruby/3533/7 "2002-12-15T06:21:35Z")

</div>

Hello Shannon,

Saturday, December 14, 2002, 5:21:23 AM, you wrote:

> I think compiling into java source code is very useful, simply for  
> political reason. If I can convert Ruby code into Java source, I can  
> easily impress my boss about the speed that I can program in Java. It is

this code will be completely unreadable and unmodifiable. ruby is  
dynamic language and translating it to java will be not better than  
sending to boss C sources of ruby implementation with “now i write  
programs in C” statement 🙂

> **···**
>
> –  
> Best regards,  
> Bulat [mailto:bulatz@integ.ru](mailto:bulatz@integ.ru)
