6

I am using JRuby along with Cucumber and is looking for a way of running

 jruby -S gem update --system
 jruby -S gem install cucumber

from within the Java ScriptEngine. No amount of Googling have let me to a solution to this problem. Basically I want to be able to do something like this

 ScriptEngineManager manager = new ScriptEngineManager();
 ScriptEngine jRubyEngine = manager.getEngineByName("jruby");
 : // some unknown code here
 jRubeEngine.eval("call gems install/update from inside JRuby")

Is there a way of accomplishing this?

1
  • In case anyone stumbles across this question, I recently created a screen cast here that might help: javajing.com/2012/06/01/ruby-from-java.html. I believe jruby-complete comes with a version of the gem command that you can make use of from java. For example, you can install the sass gem like so: java -jar jruby-complete-1.6.7.jar -S gem install -i ./sass-gems sass --no-rdoc --no-ri Commented Jul 11, 2012 at 12:25

1 Answer 1

7

RubyGems is just a Ruby library. The gem command is only a thin wrapper around the library. Everything you can do with the command, you can do with the library.

I've never actually used the library, but I guess what you want to look at is the Gem::DepencyInstaller and the code would look something like this (completely untested, just pulled out of my you-know-what):

ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine jRubyEngine = manager.getEngineByName("jruby");
String s = "
  require 'rubygems'
  require 'rubygems/dependency_installer'
  Gem::DependencyInstaller.new.install('cucumber')
";
jRubyEngine.eval(s);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.