Re: How to import classes from a runtime-defined ClassLoader?

2013-04-24 Thread Gary Trakhman
There's a lib for this, we've used it in anger, and it seems to work:

https://github.com/flatland/classlojure/blob/master/src/classlojure/core.clj


On Wed, Apr 24, 2013 at 12:01 AM, tbatchelli tbatche...@gmail.com wrote:

 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 clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 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 clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.




-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
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 clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How to import classes from a runtime-defined ClassLoader?

2013-04-24 Thread Jim
I've also had problems passing classes that reside to memory to apache 
UIMA or instantiation. What worked for me is this:


(def dynamic-classloader (. (Thread/currentThread) 
getContextClassLoader)) (Class/forName mypackage.myclass true 
dynamic-classloader)


Jim


On 24/04/13 13:39, Gary Trakhman wrote:

There's a lib for this, we've used it in anger, and it seems to work:

https://github.com/flatland/classlojure/blob/master/src/classlojure/core.clj


On Wed, Apr 24, 2013 at 12:01 AM, tbatchelli tbatche...@gmail.com 
mailto:tbatche...@gmail.com wrote:


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 clojure@googlegroups.com
mailto:clojure@googlegroups.com
Note that posts from new members are moderated - please be patient
with your first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
mailto:clojure%2bunsubscr...@googlegroups.com
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 clojure+unsubscr...@googlegroups.com
mailto:clojure%2bunsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient 
with your first post.

To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
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 clojure+unsubscr...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.




--
--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
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 clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How to import classes from a runtime-defined ClassLoader?

2013-04-24 Thread Laurent PETIT
2013/4/24 Jim jimpil1...@gmail.com:
 I've also had problems passing classes that reside to memory to apache UIMA
 or instantiation. What worked for me is this:

 (def dynamic-classloader (. (Thread/currentThread) getContextClassLoader))
 (Class/forName mypackage.myclass true dynamic-classloader)


Yes, sometimes the single-arity version of Class/forName might not be
sufficient = and jim is suggesting, using the 3-arity version helps
then. It's what I'm doing for instance in Counterclockwise (in an OSGi
context).


 Jim



 On 24/04/13 13:39, Gary Trakhman wrote:

 There's a lib for this, we've used it in anger, and it seems to work:

 https://github.com/flatland/classlojure/blob/master/src/classlojure/core.clj


 On Wed, Apr 24, 2013 at 12:01 AM, tbatchelli tbatche...@gmail.com wrote:

 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 clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 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 clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.




 --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 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 clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.




 --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 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 clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.



-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
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 clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How to import classes from a runtime-defined ClassLoader?

2013-04-23 Thread tbatchelli
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 clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
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 clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




How to import classes from a runtime-defined ClassLoader?

2013-02-27 Thread dgrnbrg
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 clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
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 clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.