On 8/15/06, Greg W. [email protected] wrote:
See, now for whatever reason, this is one of those things that my
brain is refusing to grab a hold of and just “get.”
I can understand running Ruby inside Java. Easy concept. However, I
don’t want to run Ruby inside Java, I just want to pass some data
from Ruby to Java. Have Java do some things, and then pass some data
back to Ruby. Without using web services. Once inside Java, the code
will be Java.
I’ll try to make it a bit more clear; I know that for a non-Java
programmer
it’s a little weird.
JRuby is an implementation of Ruby, plain and simple. The difference is
that
instead of being written in C and running as a C program, it’s written
in
Java and runs as a Java program. That does necessitate that it’s running
inside a JVM, like any Java program, but otherwise it works like Ruby.
You
can run “jruby script.rb” and it will run, like it would with normal
Ruby.
However you can call Java code from inside that script, and it’s pretty
easy
to do. It’s somewhat akin to Kernel#syscall for normal Ruby…you’re not
launching another process or making a remote call to call Java…JRuby
just
does some magic to make the call happen and appear to be normal Ruby
code.
Other than calls to Java, a Ruby script in JRuby looks like like a Ruby
script in normal Ruby. JRuby isn’t perfect yet, but it can run most Ruby
core libraries and simple Rails apps. It’s under heavy development, and
we’re making great progress on performance and compatibility.
That said, JRuby may or may not be the option you want. If you prefer to
use
stock Ruby, or if you’re not really into or experienced with Java in
general, JRuby may be overkill for your needs. The Ruby/Java bridges
would
allow you, theoretically, to call your Java library of choice as in
JRuby
with only a little more overhead. You’ll need to choose what works for
you.
JRuby is usually the best option if you have Java libraries you want to
be
able to use from your Ruby code, but it’s not always the best option and
certainly not the only option. If you do choose to go down the JRuby
route,
the other devs and I will certainly try to help you make your app work
right.
Incidentally, there’s now an additional option for remoting with JRuby:
DRb.
Apparently some users now have DRb working well enough under JRuby that
you
could put your Java code behind a DRb service rather than behind a SOAP
web
service. That’s pretty compelling considering the complexity and
overhead of
SOAP. We also have plans in the future to implement “smart” proxies to
map
DRb automatically to the various types of Java EE services.