(resolve-class this name)
Given a class name, return that typeref's class bytes as an InputStream.
;;Check if class c exists on the classpath
(require '[clojure.reflect :refer [resolve-class]])
(defn class-exists? [c]
(resolve-class (.getContextClassLoader (Thread/currentThread)) c))
(class-exists? 'org.joda.time.DateTime)
;;=> nil
;; Obtaining a suitable class loader is an important consideration.
;; to a large degree the class loader used by default is the
;; context class loader which is controlled by
*use-context-classloader*
;=> true
;; the following helper function shows the
(require '[clojure.java.classpath :as cp])
;=> nil
;; the context class loader
(def ccl (.getContextClassLoader (Thread/currentThread)))
;=> #'boot.user/ccl
(cp/classpath ccl)
;=> (#object[java.io.File 0x709e8101 ...
;; the system class loader
(def scl (java.lang.ClassLoader/getSystemClassLoader))
;=> #'boot.user/scl
(cp/classpath scl)
;=> (#object[java.io.File 0x709e8101 ...
;; the class loader used to load a particular class instance.
(deftype Foo [bar])
;=> boot.user.Foo
(def icl (.getClassLoader (class (Foo. 4))))
;=> #'boot.user/icl
(cp/classpath icl)
;=> (#object[java.io.File 0x709e8101 ...
;; I recommend you use the DynamicClassLoader
;; for cases when 'import' does not do it.
;; https://github.com/clojure/clojure
(def dcl (clojure.lang.DynamicClassLoader.))
;=> #'boot.user/dcl
(cp/classpath dcl)
;=> (#object[java.io.File 0x709e8101 ...