Does the / forName class in Clojure not comply with ContextClassLoader?

I connected to the running service and had var pointing to the classloader with which the plugin was loaded (with installation my.package).

DynamicClassLoader used by REPL does not include the plugin I want to interact with; I want to be able to work with classes loaded from the plugin, despite this limitation.

The following works:

=> (.loadClass plugin-classloader "my.package.MyClass")
my.package.MyClass

... while the following does not allow (explicitly overriding the stream class loader):

=> (do
     (.setContextClassLoader (Thread/currentThread) plugin-classloader)
     (Class/forName "my.package.MyClass"))
ClassNotFoundException my.package.MyClass  java.net.URLClassLoader$1.run (URLClassLoader.java:202)

... and does not (explicitly overriding the thread context class loader and the clojure.lang.Compiler / LOADER link):

=> (let [dcl (clojure.lang.DynamicClassLoader. plugin-classloader)]
     (.setContextClassLoader (Thread/currentThread) dcl)
     (with-bindings* {clojure.lang.Compiler/LOADER dcl}
       (eval '(pr-str (Class/forName "my.package.MyClass")))))
ClassNotFoundException my.package.MyClass  java.net.URLClassLoader$1.run (URLClassLoader.java:202)

... and does not do this:

=> my.package.MyClass
CompilerException java.lang.ClassNotFoundException: my.package.MyClass, compiling:(NO_SOURCE_PATH:0)

Class.forName() ? , ; ClassNotFoundExceptions, .


, , , Clojure DynamicClassLoader ( BundleClassLoader plugin-classloader var) :

=> (e)
java.lang.ClassNotFoundException: my.package.MyClass
 at java.net.URLClassLoader$1.run (URLClassLoader.java:202)
    java.security.AccessController.doPrivileged (AccessController.java:-2)
    java.net.URLClassLoader.findClass (URLClassLoader.java:190)
    clojure.lang.DynamicClassLoader.findClass (DynamicClassLoader.java:61)
    java.lang.ClassLoader.loadClass (ClassLoader.java:306)
    java.lang.ClassLoader.loadClass (ClassLoader.java:247)
    java.lang.Class.forName0 (Class.java:-2)
    java.lang.Class.forName (Class.java:169)
+5
1

clojure.lang.Compiler/eval, REPL, clojure.lang.Compiler/LOADER, . var , eval - :

=> (let [dcl (clojure.lang.DynamicClassLoader. plugin-classloader)]
     (with-bindings {clojure.lang.Compiler/LOADER dcl}
       (eval '(Class/forName "my.package.MyClass"))))
my.package.MyClass
+5
source

All Articles