Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # The following statement executes a Java class that uses XMLDecoder to instantiate
- # a class from an XMLEncoded xml file. I have required the jar that has the class being
- # instantiated. I can create an instance of the class directly however when I execute
- # this code I get a ClassNotFoundException.
- #
- bundleManager.addBundles(configUrl.openStream)
- java.lang.ClassNotFoundException: net.sf.sail.core.service.impl.CurnitUrlProviderImpl
- #
- # I think the reason is because XMLDecoder uses a thread context classloader
- # and bypasses the JRuby class loader.
- #
- # Some forensics:
- #
- # make a new instance of a random class I loaded from a jar I required
- #
- b = SailCoreBundle::BundleManager.new
- # => #<Java::NetSfSailCoreBundle::BundleManager:0x3c43e5 @java_object=net.sf.sail.core.bundle.BundleManager@8d9a14>
- #
- # get the JRuby classloader
- #
- jcl = b.getClass.getClassLoader
- # => #<Java::OrgJrubyUtil::JRubyClassLoader:0xe646e8 @java_object=org.jruby.util.JRubyClassLoader@33788d>
- #
- # get the current thread
- #
- t = java.lang.Thread.currentThread
- # => #<Java::JavaLang::Thread:0xdd7c4b @java_object=Thread[main,5,main]>
- #
- # get the thread context classloader
- #
- tcl = t.getContextClassLoader
- # => #<#<Class:01xc901e4>:0x9b3c58 @java_object=sun.misc.Launcher$AppClassLoader@a9c85c>
- #
- # the thread context classloader is the parent of the JRuby classloader
- #
- jcl.getParent == tcl
- # => true
Add Comment
Please, Sign In to add comment