Skip to content

Instantly share code, notes, and snippets.

@kohyama
Created July 30, 2012 05:43
Show Gist options
  • Save kohyama/3205162 to your computer and use it in GitHub Desktop.
Save kohyama/3205162 to your computer and use it in GitHub Desktop.
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