JRuby and Ruby integration

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…

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

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?

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

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

Thanks for your thoughts Fred…

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?

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 :wink: ): 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/

Thanks,
–Vladimir

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/