troubleshooting classloader problems

3 views
Skip to first unread message

Stuart Halloway

unread,
Oct 28, 2008, 9:48:03 AM10/28/08
to clo...@googlegroups.com
Hi all,

When I am troubleshooting classloader problems I find myself wanting
to know the list of URLs currently on the classpath. I didn't find
this exposed anywhere, so I wrote the functions below.

Usage:

(take 3 (classpath-url-seq))
-> ("file:/Users/stuart/relevance/personal/SHCLOJ_svn/Book/code/"
"file:/Users/stuart/repos/clojure-contrib/clojure-contrib.jar"
"file:/Users/stuart/devtools/java/joda-time-1.5.2/joda-
time-1.5.2.jar")

Of course to be most helpful this needs to be in clojure.jar --
otherwise you might have classloader problems loading the classloader
help code. :-) Not sure if this is general enough to deserve to be in
clojure.jar, but you're welcome to it if others find it useful.

Stuart

; -------------------------------------------------------
(defn classloader-seq
([] (classloader-seq (clojure.lang.RT/baseLoader)))
([cl]
(loop [loaders (vector cl)]
(if (nil? (last loaders))
(drop-last loaders)
(recur (conj loaders (.getParent (last loaders))))))))

(defn classpath-url-seq [& args]
(map (memfn toExternalForm)
(reduce concat
(map (memfn getURLs)
(apply classloader-seq args)))))


Allen Rohner

unread,
Oct 28, 2008, 11:22:57 AM10/28/08
to Clojure
I like it. I think it is a good idea to put it in clojure.jar. It
certainly helps troubleshooting.

Allen
Reply all
Reply to author
Forward
0 new messages