This worked for me:

(with-bindings {clojure.lang.Compiler/LOADER dcl} ...)

(from: 
http://stackoverflow.com/questions/10941330/class-forname-in-clojure-not-respecting-contextclassloader
 
)

On Wednesday, February 27, 2013 9:45:32 AM UTC-8, dgrnbrg wrote:
>
> I am trying to include some Groovy code at runtime, which is already on 
> the JVM's classloader path. I have succeeded in setting the 
> groovy.lang.GroovyClassLoader with Clojure's classloader as the Thread's 
> contextClassLoader, but I'm having troubling getting (import ...) to work. 
> I discovered so far that (import ...) prefers to use the 
> clojure.lang.Compiler/LOADER if it's defined (and it is, in my project), so 
> I tried the following:
>
> (try
>   (push-thread-bindings {clojure.lang.Compiler/LOADER 
> (groovy.lang.GroovyClassLoader.)}
>   ;GroovyCL defaults to use contextClassLoader as parent, which is the 
> Clojure ClassLoader
>   (import 'my_groovy_class)
>   (finally (pop-thread-bindings)))
>
> Note that I can successfully do (.. Thread currentThread 
> getContextClassLoader (loadCLass "my_groovy_class")) once I've set the 
> contextClassLoader.
>
> What is the way to get (import ...) working so that I can manipulate 
> my_groovy_class without resorting to forName/createInstance?
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to