Hi everyone,
I am on a project integrating a JRuby on Rails web frontend into a
large existing java codebase. Due to some other requirements, there
are some interfaces that I can’t put on the standard JRuby classpath,
I have to load them using a custom class loader like this:
def load_interface
protocol = “file”
host = “localhost”
filepath = Rails.root.parent + “build/classes”
url = URL.new protocol, host, filepath.to_s.to_java_string
urlcl = URLClassLoader.new([url].to_java java.net.URL)
interfac_ename = "com.company1.Interface1
interface_class = java.lang.Class.forName(interface_name, true,
urlcl)
return interface_class
end
So, this method returns a Java class. Now, I need to get a JRuby
Module m from this Java interface so that I can do call
some_jruby_object.extend(m) because I need to provide an
implementation. I’ve tried calling “JavaUtilities.get_interface_module
interface_class”, but I get an error then:
ArgumentError: expected JavaClass, got interface com.company1.Interface1
I am not sure how to convert the interface that I loaded into an
instance of the JavaClass object. I noticed that there is a
JavaClass.get method, but in addition to the actual class parameter it
also takes a Runtime parameter, and I am not sure where to find that
object. Also, I am not sure whether I am at all going down the right
direction here, and maybe I am missing something obvious that doesn’t
require calling “get_interface_module”.
Thank you!