Created
August 23, 2012 01:15
-
-
Save martinlau/3431027 to your computer and use it in GitHub Desktop.
Classloader swapping in Clojure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro do-with-classloader | |
[classloader & body] | |
`(let [old-classloader# (.getContextClassLoader (Thread/currentThread))] | |
(.setContextClassLoader (Thread/currentThread) ~classloader) | |
(try ~@body | |
(finally (.setContextClassLoader (Thread/currentThread) old-classloader#))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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