Skip to content

Instantly share code, notes, and snippets.

@kohyama kohyama/dce.clj
Created Jul 30, 2012

Embed
What would you like to do?
Add paths of sources and classes of your program, compile and execute it. Do them all at runtime.
(ns dce.core
(:import java.net.URL clojure.lang.DynamicClassLoader)
(:gen-class))
(defn -main [abs-path target-ns & args]
(let [ccl (.getContextClassLoader (Thread/currentThread))
dcl (if (instance? DynamicClassLoader ccl) ccl
(let [l (DynamicClassLoader. ccl)]
(.setContextClassLoader (Thread/currentThread) l)
l))]
(.addURL dcl (URL. (str "file://" abs-path "/src/")))
(.addURL dcl (URL. (str "file://" abs-path "/classes/")))
(binding [*compile-path* (str abs-path "/classes")]
(compile (symbol target-ns)))
(def f (future (apply (resolve (symbol (str target-ns "/-main"))) args)))
(Thread/sleep 5000)
(future-cancel f)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.