Calling Jruby -S from a java code

Hi,
I am trying to integrate JRuby with some other java programs I’m using.
I managed to pack jruby with all the required gems inside the
jruby-complete.jar file.
The problem is about how to load gems in my ruby program.

Think of the following -two line ruby script - file, called script.rb

require ‘rubygems’
require ‘mongrel’

I can execute this program by simply running this on the command line:

java -jar jruby-complete.jar -S script.rb

Now I want to achive the same effect through a java program, here is my
code (borrowed from another post in this list) :

String[] jrubyArgs = new String[2 + args.length];
jrubyArgs[0] = "-S";
jrubyArgs[1] = "script.rb";
for (int i = 2; i < 2 + args.length ; i++) {
   jrubyArgs[i] = args[i - 2];
}
org.jruby.Main.main(jrubyArgs);

When I execute the following program, I get:

script.rb:3:in `require’: no such file to load – rubygems (LoadError)

I appreciate any comments on this issue or any idea how shall I fix
this.

Cheers,

-A


Ali S., Research Assistant, LSIR - Distributed Information Systems
Laboratory
EPFL-IC-IIF-LSIR, Bâtiment BC, Station 14, CH-1015 Lausanne, Switzerland.
http://lsirpeople.epfl.ch/salehi/
email: [email protected]
Tel: +41-21-693.6656/7563 Mobile: +41-21-78.815.2020 Fax:
+41-21-693.8115


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Mon, Jul 28, 2008 at 11:42 AM, Ali S. [email protected] wrote:

jrubyArgs[1] = “script.rb”;
for (int i = 2; i < 2 + args.length ; i++) {
jrubyArgs[i] = args[i - 2];
}
org.jruby.Main.main(jrubyArgs);

When I execute the following program, I get:

script.rb:3:in `require’: no such file to load – rubygems (LoadError)

Rubygems is actually packaged inside the complete jar in a special
place: META-INF/jruby.home/lib/ruby/site_ruby/1.8. You can try adding
it to the load path, which should allow you to load rubygems out of
the jar file.

$LOAD_PATH << ‘META-INF/jruby.home/lib/ruby/site_ruby/1.8’

Cheers,
/Nick


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email