Loading jRuby-generated .class files in

I’ve generated a .class file with the following script:

require ‘jruby/core_ext’

class Example
def initialize
puts “Hello from jRuby-land!”

become_java! ‘.’

A different JVM reads the .class file into a byte array and loads it
like this:

Ruby runtime = Ruby.newInstance();
ClassReader cr = new ClassReader(bytes);
String className = cr.getClassName().replace(’/’, ‘.’);

ClassDefiningJRubyClassLoader oscl = new
Class<?> klass = oscl.defineClass(className, klass);

I get a Java Class back, but I’m not able to instantiate it. If I call
klass.newInstance(), I get a NullPointerException. I’m sure I’ve made
this much harder than it should be, but I haven’t found any clues
digging through the jRuby project.

I feel like this is really close to working, but I don’t think I’ll get
there on my own. Any help would be greatly appreciated. Thanks!