Calling JRuby from Ruby.

C

Chris Richards

Whats the best way of running a JRuby script from Ruby?

I know you can do this : `jruby script.rb`, but that won't allow passing
of parameters from ruby to jruby.

You could pass parameters by passing the Object.inspect string and then
doing an eval:


`jruby script/rb #{object.inspect}`
 
R

Robert Dober

Whats the best way of running a JRuby script from Ruby?

I know you can do this : `jruby script.rb`, but that won't allow passing
of parameters from ruby to jruby.

You could pass parameters by passing the Object.inspect string and then
doing an eval:


`jruby script/rb #{object.inspect}`
.

I suppose you could serialize your objects/parameters and pass it though
that way.

Any decent ideas?
Hmm are Ruby and JRuby drb compatible? Maybe that would do the trick for you?
Would be great BTW.
Thanks
Chris
Cheers
Robert
 
R

Robert Dober

Hmm are Ruby and JRuby drb compatible? Maybe that would do the trick for you?
Would be great BTW.
I just downloaded JRuby 1.0, JRuby as Server or client, Ruby as client
or server, does not matter works out of the box, like charm.
Chris this really should do the trick for you, no?
Something like :
Ruby:
-------
require 'drb'
class MyParams
attr_reader :value
def initialize value
@val = value
end
end

DRb.start_service("druby://localhost:4646", MyParams.new(
theObjectYouWant2Pass ));

system "jruby... " ### this might be tricky, use either fork or Threading
sleep 42
DRb.stop_service
=============================================
And in JRuby

require 'drb'
DRb.start_service
incoming = DRbObject.new(nil, "druby://localhost:4646")
object = incoming.value
DRb.stop_service

do whatever you want with value...


HTH
Robert
 
C

Chris Richards

DRb is the answer and it does work like a charm!!

So now i can have a jruby drb server purely dedicated to just creating
nice JFreeChart charts for me!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,199
Latest member
AnyaFlynn6

Latest Threads

Top