Skip to content

Instantly share code, notes, and snippets.

@martinlau
Created August 23, 2012 01:15
Show Gist options
  • Save martinlau/3431027 to your computer and use it in GitHub Desktop.
Save martinlau/3431027 to your computer and use it in GitHub Desktop.
Classloader swapping in Clojure
(defmacro do-with-classloader
[classloader & body]
`(let [old-classloader# (.getContextClassLoader (Thread/currentThread))]
(.setContextClassLoader (Thread/currentThread) ~classloader)
(try ~@body
(finally (.setContextClassLoader (Thread/currentThread) old-classloader#)))))
(do-with-classloader classloader
(prn "hi")
(prn "bye"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment