Guest User

Untitled

a guest
Apr 22nd, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. #
  2. # The following statement executes a Java class that uses XMLDecoder to instantiate
  3. # a class from an XMLEncoded xml file. I have required the jar that has the class being
  4. # instantiated. I can create an instance of the class directly however when I execute
  5. # this code I get a ClassNotFoundException.
  6. #
  7. bundleManager.addBundles(configUrl.openStream)
  8. java.lang.ClassNotFoundException: net.sf.sail.core.service.impl.CurnitUrlProviderImpl
  9. #
  10. # I think the reason is because XMLDecoder uses a thread context classloader
  11. # and bypasses the JRuby class loader.
  12. #
  13. # Some forensics:
  14. #
  15. # make a new instance of a random class I loaded from a jar I required
  16. #
  17. b = SailCoreBundle::BundleManager.new
  18. # => #<Java::NetSfSailCoreBundle::BundleManager:0x3c43e5 @java_object=net.sf.sail.core.bundle.BundleManager@8d9a14>
  19. #
  20. # get the JRuby classloader
  21. #
  22. jcl = b.getClass.getClassLoader
  23. # => #<Java::OrgJrubyUtil::JRubyClassLoader:0xe646e8 @java_object=org.jruby.util.JRubyClassLoader@33788d>
  24. #
  25. # get the current thread
  26. #
  27. t = java.lang.Thread.currentThread
  28. # => #<Java::JavaLang::Thread:0xdd7c4b @java_object=Thread[main,5,main]>
  29. #
  30. # get the thread context classloader
  31. #
  32. tcl = t.getContextClassLoader
  33. # => #<#<Class:01xc901e4>:0x9b3c58 @java_object=sun.misc.Launcher$AppClassLoader@a9c85c>
  34. #
  35. # the thread context classloader is the parent of the JRuby classloader
  36. #
  37. jcl.getParent == tcl
  38. # => true
Add Comment
Please, Sign In to add comment