Skip to content

Instantly share code, notes, and snippets.

@byteit101
Last active February 1, 2022 01:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save byteit101/0c72c4b57212dbd778b6a6e41f0389f4 to your computer and use it in GitHub Desktop.
Save byteit101/0c72c4b57212dbd778b6a6e41f0389f4 to your computer and use it in GitHub Desktop.
JRuby Class loader proxy
# FXML requires loading both ruby and java classes.
# JRuby has no such single classloader builtin, so we proxy them all
# This is a minimal classloader only for classes, resources not supported
class PolyglotClassLoader < java.lang.ClassLoader
def initialize()
super(JRuby.runtime.jruby_class_loader)
end
java_signature "java.lang.Class findClass(java.lang.String name)"
def findClass(a)
# TODO: full Ruby modules?
begin # TODO: become_java! idempotent?
return Object.const_get(a.split(".").last).tap{|x| x.become_java!}.java_class
rescue NameError
raise java.lang.ClassNotFoundException.new("Could not find ruby class #{a}!") # Must be a java CNF, not a Ruby Name Error
end
end
become_java!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment