Can't call JRuby Scriptlet from Java

I'm completely new to IntelliJ, coming from a mixed Eclipse+RubyMine environment, but evaluating IntelliJ for it's good Ruby integration.

I'm trying to get a really simple example working with JRuby integration in a Java project. I'm using IntelliJ 13.0.2 with latest Ruby plugin. I have a simple JUnit test case which basically just calls into JRuby:

String rubyFile = "test_ruby.rb"
ScriptingContainer container = new ScriptingContainer();
 container.setCompatVersion(org.jruby.CompatVersion.RUBY1_9);
logger.info("Calling ScriptLet");
 container.runScriptlet(PathType.ABSOLUTE, rubyFile);
logger.info("Done with ScripLet");

My project uses Maven, and everything works fine from command line running "mvn test".

But if I try to execute the test case from within IntelliJ, it fails immediately:

2014-02-12 09:37:51,094  INFO [main] (TestJRubyBinding.test) Calling ScriptLet

org.jruby.exceptions.RaiseException: (TypeError) can't convert nil into String
 at org.jruby.RubyFile.join(org/jruby/RubyFile.java:1931)
 at org.jruby.RubyFile.join(org/jruby/RubyFile.java:831)
 at RUBY.ConfigFile(/Users/peter/.rvm/rubies/jruby-1.7.10/lib/ruby/shared/rubygems/config_file.rb:89)
 at RUBY.(root)(/Users/peter/.rvm/rubies/jruby-1.7.10/lib/ruby/shared/rubygems/config_file.rb:37)
 at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1083)
 at RUBY.(root)(/Users/peter/.rvm/rubies/jruby-1.7.10/lib/ruby/shared/rubygems/defaults/jruby.rb:1)
 at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1083)
 at RUBY.(root)(/Users/peter/.rvm/rubies/jruby-1.7.10/lib/ruby/shared/rubygems/defaults/jruby.rb:1)
 at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1083)
 at RUBY.(root)(/Users/peter/.rvm/rubies/jruby-1.7.10/lib/ruby/shared/rubygems.rb:1)
 at org.jruby.RubyKernel.load(org/jruby/RubyKernel.java:1099)
 at RUBY.(root)(/Users/peter/.rvm/rubies/jruby-1.7.10/lib/ruby/shared/rubygems.rb:1203)

Looking into the config_file.rb, the offending statement seems to be:

SYSTEM_WIDE_CONFIG_FILE = File.join system_config_path, 'gemrc'

I.e. system_config_path is nil, which indicates some kind of JRuby configuration problem in the way IntelliJ initializes JRuby. Same code works fine from command line and from within Eclipse.

I have checked all the obvious places, the execution uses the right Ruby SDK etc, but something very basic seems to be wrong.

Any ideas on how to setup IntelliJ to get this working?

Please sign in to leave a comment.