We wanted to implement a class in JRuby that implements a Java interface, to fulfill a dependency injection contract. This is seemingly (unfortunately) a much more difficult task than it sounds.
So, here's our simple Java interface that defines one public method, "indexObject":
Unfortunately, here's what that compiles to (using jrubyc):
publicclassDemoRubySolrIndexerextendsRubyObject{privatestaticfinalRuby__ruby__=Ruby.getGlobalRuntime();privatestaticfinalRubyClass__metaclass__;static{Stringsource=newStringBuilder("require 'java'\n"+"require 'rubygems'\n"+"require 'active_fedora'\n"+"\n"+"java_package 'org.fcrepo.indexer.solr'\n"+"class DemoRubySolrIndexer\n"+" include org.fcrepo.indexer.solr.ScriptIndexer\n"+" \n"+
That's not a ScriptIndexer instance! In the end, we gave in and ended up using the spring-lang dynamic language support (for jruby, groovy and beanshell only):
I assume, under the hood, this makes a similar proxy class, but does so a little smarter. It's annoying we have to tie ourselves so tightly to Spring to get this to work, without writing some unnecessary Proxy classes ourselves.