Forum: JRuby Loading jRuby-generated .class files in

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Kyle K. (Guest)
on 2015-06-22 10:47
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!
This topic is locked and can not be replied to.