This is still a problem, since the jruby compiler is still creating RubyObject for classes.
The only workaround I know is to use JRuby ScriptEngine from Java to evaluate your JRuby code. For example, here is some JRuby code:
require 'java' java_import 'javax.swing.JFrame' java_import 'javax.swing.JButton' class MyFrame < JFrame def initialize super('Test') content_pane.add(JButton.new("Hello")) pack() end end
Then this code can be called from the Java class as follows:
import javax.swing.JFrame; import javax.script.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("jruby"); Reader reader = new FileReader("myframe.rb"); engine.eval(reader);
Here, the object returned by eval can be placed in a JFrame , as you would expect. See also this question for this problem.
source share