Raymond Lee wrote:
> I just downloaded jruby and looked at the samples, but I couldn't see
> documentations or samples show how to invoke Ruby scripts from Java
> applications. I tried
> Runtime.getRuntime().exec("jruby swing.rb"); , but it didn't work. Any
> ideas??

This discussion should probably be at the jruby-user list, but anyway:

If you just need to invoke Ruby scripts, with little or no exchange of
data between them and Java, then you won't even need JRuby. Just launch
the Ruby interpreter from Java, with something like the code you're
using above.

The exec() command that you use runs things outside of Java, which may
or may not be what you want. In any case it's not the best way to use
JRuby.

Try something like this from Java to run Ruby code:

Ruby runtime = Ruby.getDefaultInstance(null);
runtime.evalScript("puts 'hello'");

(I haven't tested the above code, but something like it should work. :-)

> Also, is it possible to pass Java variables in Java program to jruby
> scripts. It needs some kind of bindings..

JRuby has support for accessing Java objects, so with a little ingenuity
you should find a way to get the data you need across. Java's system
properties could be usable for this.

/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...