i want to make it easier to add jars that contain precompiled native
libraries to clojars. currently, to do this, you can use the lein
native-deps plugin, but users of your jar still have to know that it
has native dependencies, add them as :native-dependencies to
project.clj and run 'lein native_deps'. then they have to modify
LD_LIBRARY_PATH or java.libary.path by hand. this is much more
complicated than it should be. they should just have add the
dependency, type 'lein deps', and everything else should just work.
so, i've spent some time writing a custom classloader
(NativeClassLoader) that overrides findLibrary to locate and load
native library files transparently within jars. it works great, but in
the process of working on it, i ran into some code in the clojure
source that doesn't quite make sense to me.
i need to insert NativeClassLoader between
clojure.lang.DynamicClassLoader and sun.misc.Launcher$AppClassLoader.
i did this in the clojure code in two places:
1. clojure/main.clj at the top of the repl function
2. clojure/lang/RT.java inside of makeClassLoader
i guess i don't fully understand makeClassLoader and baseLoader.
makeClassLoader is called from Compile.java in three different places
(compile, eval and load). makeClassLoader wraps baseLoader with a
DynamicClassLoader, but it is happening multiple times. for example,
in master:
user=> (clojure.lang.RT/baseLoader)
#<DynamicClassLoader clojure.lang.DynamicClassLoader@70e35d5>
user=> (.getParent (clojure.lang.RT/baseLoader))
#<DynamicClassLoader clojure.lang.DynamicClassLoader@45b34126>
user=> (.getParent (.getParent (clojure.lang.RT/baseLoader)))
#<AppClassLoader sun.misc.Launcher$AppClassLoader@6ba7bf11>
the delegation hierarchy looks like this:
DynamicClassLoader -> DynamicClassLoader -> AppClassLoader
and when i insert NativeClassLoader, it looks like this:
DynamicClassLoader -> NativeClassLoader -> DynamicClassLoader ->
NativeClassLoader -> AppClassLoader
is this a bug? it seems like makeClassLoader should always wrap the
application classloader, not baseLoader, but there may be something
i'm missing. any help or advice would be appreciated. i'd like to open
source NativeClassLoader so everyone can benefit from it. is this
something others would find useful? Rich would you consider a patch to
clojure for this?
thanks,
Justin Balthrop
--
You received this message because you are subscribed to the Google Groups "Clojure Dev" group.
To post to this group, send email to
cloju...@googlegroups.com.
To unsubscribe from this group, send email to
clojure-dev...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/clojure-dev?hl=en.