Skip to content

Instantly share code, notes, and snippets.

@cowboyd
Created October 29, 2010 11:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cowboyd/653397 to your computer and use it in GitHub Desktop.
Save cowboyd/653397 to your computer and use it in GitHub Desktop.
Why can't JRuby find it's
@Extension
public class RubyExtensionFinder extends ExtensionFinder {
public RubyExtensionFinder() {
ScriptingContainer jruby = new ScriptingContainer();
/**
* When run in the maven test suite, this line executes just fine
* but when instantiated by the Hudson server at runtime, gets the
* following error: no such file to load -- builtin/core_ext/symbol
*
* What's the conventional way to help Jruby find its way home through
* a complex forest of class loaders?
*/
/**
* the answer is this line right here. If I understand correctly, it makes
* sure that the ScriptContainer uses the same class loader for scripts as
* the one that loaded _it_ that way, it can find the jruby-complete.jar
* that contains the stardard ruby library.
*/
jruby.setClassLoader(jruby.getClass().getClassLoader());
jruby.runScriptlet("puts 'Hello From Hudson Extension Finder!'");
}
public <T> Collection<ExtensionComponent<T>> find(Class<T> tClass, Hudson hudson) {
System.out.printf("find(%s)\n", tClass.getName());
return new ArrayList<ExtensionComponent<T>>();
}
}
@yokolet
Copy link

yokolet commented Oct 29, 2010

If you are using jruby.jar, would you try jruby.setHomeDirectory([jruby's home directory here])? Unless, jruby.setClassLoader(jruby.getClass().getClassLoader()) or setting some suitable classloader might work.

@cowboyd
Copy link
Author

cowboyd commented Oct 29, 2010

adding

ruby.setClassLoader(jruby.getClass().getClassLoader())

seems to do the trick. thanks!

@yokolet
Copy link

yokolet commented Oct 29, 2010

Good to know that. You're welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment