# JRuby and Ruby integration

**URL:** <https://www.ruby-forum.com/t/jruby-and-ruby-integration/134247>\
**Category:** Rails\
**Created:** [April 9, 2008, 9:08am UTC](https://www.ruby-forum.com/t/jruby-and-ruby-integration/134247 "2008-04-09T09:08:46Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![karthikeyan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/898d66/32.png) [@karthikeyan](https://www.ruby-forum.com/u/karthikeyan)\
**Post date:** [April 9, 2008, 9:08am UTC](https://www.ruby-forum.com/t/jruby-and-ruby-integration/134247/1 "2008-04-09T09:08:46Z")

</div>

Hi,

I have developed an application using ROR. For one feature, now I have  
to use JRuby. I have installed JRuby in my system.

I included the follwing statement in my controller.

include Java

I got the following error.

“uninitialized constant Java (NameError)”

This is because the file is executes using “ruby” command. But when I  
run the file as a stand-alone program using “jruby” command, it executed  
successfully. But it is not working with my application.

Can i force the interpreter to use “jruby” command only for this file?

Is there any way to solve this issue?

Thanks in advance…

---

<div class="post-metadata">

**Author:** ![karthikeyan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/898d66/32.png) [@karthikeyan](https://www.ruby-forum.com/u/karthikeyan)\
**Post date:** [April 9, 2008, 9:20am UTC](https://www.ruby-forum.com/t/jruby-and-ruby-integration/134247/2 "2008-04-09T09:20:13Z")

</div>

On 9 Apr 2008, at 08:08, Karthi kn wrote:

> I got the following error.
> 
> “uninitialized constant Java (NameError)”
> 
> This is because the file is executes using “ruby” command. But when I  
> run the file as a stand-alone program using “jruby” command, it  
> executed  
> successfully. But it is not working with my application.
> 
> Can i force the interpreter to use “jruby” command only for this file?

Can you just run the whole app using jruby?

Fred

---

<div class="post-metadata">

**Author:** ![karthikeyan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/898d66/32.png) [@karthikeyan](https://www.ruby-forum.com/u/karthikeyan)\
**Post date:** [April 9, 2008, 9:24am UTC](https://www.ruby-forum.com/t/jruby-and-ruby-integration/134247/3 "2008-04-09T09:24:56Z")

</div>

I am not sure. I have just started exploring on JRuby. I installed jruby  
and added the needed code in my controller and tried to run the  
application normally.

That is an application created with ruby but not jruby.

Can we run the appilcation using jruby?

---

<div class="post-metadata">

**Author:** ![karthikeyan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/898d66/32.png) [@karthikeyan](https://www.ruby-forum.com/u/karthikeyan)\
**Post date:** [April 9, 2008, 9:33am UTC](https://www.ruby-forum.com/t/jruby-and-ruby-integration/134247/4 "2008-04-09T09:33:42Z")

</div>

On 9 Apr 2008, at 08:24, Karthi kn wrote:

> I am not sure. I have just started exploring on JRuby. I installed  
> jruby  
> and added the needed code in my controller and tried to run the  
> application normally.
> 
> That is an application created with ruby but not jruby.
> 
> Can we run the appilcation using jruby?  
> jruby’s certainly aims to be able to do anything the ruby can (but  
> just happens to run on the jvm). Unless you’ve got lots of ruby  
> extensions (which contain c code and so do require work to be ported  
> to jruby) it’s certainly worth a go.

Fred

---

<div class="post-metadata">

**Author:** ![karthikeyan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/898d66/32.png) [@karthikeyan](https://www.ruby-forum.com/u/karthikeyan)\
**Post date:** [April 9, 2008, 10:38am UTC](https://www.ruby-forum.com/t/jruby-and-ruby-integration/134247/5 "2008-04-09T10:38:27Z")

</div>

On 9 Apr 2008, at 09:22, Karthi kn wrote:

> But now, I think, it is not possible to do that in my application  
> because I have created my whole application using Ruby but not JRuby.

I’m by no means a jruby expert (I’ve read about it, but haven’t used  
it properly, just for tinkering), but in theory it is just another  
version of ruby and should be able to run your app just as well as the  
standard MRI ruby.

Fred

---

<div class="post-metadata">

**Author:** ![karthikeyan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/898d66/32.png) [@karthikeyan](https://www.ruby-forum.com/u/karthikeyan)\
**Post date:** [April 9, 2008, 10:55am UTC](https://www.ruby-forum.com/t/jruby-and-ruby-integration/134247/6 "2008-04-09T10:55:32Z")

</div>

Thanks for your thoughts Fred…

---

<div class="post-metadata">

**Author:** ![karthikeyan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/898d66/32.png) [@karthikeyan](https://www.ruby-forum.com/u/karthikeyan)\
**Post date:** [April 9, 2008, 10:22am UTC](https://www.ruby-forum.com/t/jruby-and-ruby-integration/134247/7 "2008-04-09T10:22:50Z")

</div>

My application is a big one. It’s almost completed. Now my requirement  
is to create crystal report from my application by passing my query  
results as XML to the crystal report template.

For this Crystal Report implementation, there is no API in ROR. But API  
is available for Java-CrystalReport integration. So I planned to use the  
JRuby to utilize the Java libraries.

But now, I think, it is not possible to do that in my application  
because I have created my whole application using Ruby but not JRuby.

What is your opinion on this?

---

<div class="post-metadata">

**Author:** ![karthikeyan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/898d66/32.png) [@karthikeyan](https://www.ruby-forum.com/u/karthikeyan)\
**Post date:** [April 9, 2008, 11:43am UTC](https://www.ruby-forum.com/t/jruby-and-ruby-integration/134247/8 "2008-04-09T11:43:43Z")

</div>

Hi,

For those options that are JRuby specific, you could add a conditional  
in your code, like:

if RUBY\_PLATFORM =~ /java/

# jruby-specific code here

end

As for some of your other questions. Typically, jruby behaves as just  
a ruby replacement, and in most cases that’s all you need to do – to  
invoke jruby instead of ruby.  
(There are cases, like native C extensions, are not supported by  
JRuby).

Well, in case of Rails, you’d also need to adjust your database config  
to specify proper adapter.

JRuby works great with either webrick or mongrel.

There is much more info on “JRuby on Rails” on JRuby wiki (which is  
unfortunately down at the moment 😉 ): [http://wiki.jruby.org/](http://wiki.jruby.org/)

But I have my own “120 seconds guide to JRuby on Rails” here:  
[http://blog.emptyway.com/2008/04/08/120-seconds-guide-to-jruby-on-rails/](http://blog.emptyway.com/2008/04/08/120-seconds-guide-to-jruby-on-rails/)

Thanks,  
–Vladimir

---

<div class="post-metadata">

**Author:** ![karthikeyan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/898d66/32.png) [@karthikeyan](https://www.ruby-forum.com/u/karthikeyan)\
**Post date:** [April 10, 2008, 12:00am UTC](https://www.ruby-forum.com/t/jruby-and-ruby-integration/134247/9 "2008-04-10T00:00:42Z")

</div>

You probably need to use JRuby for the whole stack.

Whatever is executing your server needs to be run by jruby, not ruby.

Julian.

Learn Ruby on Rails! Check out the FREE VIDS (for a limited time)  
VIDEO #3 out NOW!  
[http://sensei.zenunit.com/](http://sensei.zenunit.com/)
