Forum: JRuby Loading jRuby-generated .class files in 9.0.0.0.rc1

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
677bd16c9ee50023750cd41bccf2842f?d=identicon&s=25 Kyle King (kylekyle)
on 2015-06-22 08:47
I've generated a .class file with the following script:

require 'jruby/core_ext'

class Example
  def initialize
    puts "Hello from jRuby-land!"
  end

  become_java! '.'
end

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
ClassDefiningJRubyClassLoader(runtime.getJRubyClassLoader());
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!
This topic is locked and can not be replied to.