Last active
April 22, 2016 07:23
-
-
Save zentrope/f5530caf1fd96229bb89dc393d759812 to your computer and use it in GitHub Desktop.
Find out the jar you're running 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
(ns engine.lib.utils | |
(:require | |
[clojure.string :as s] | |
[clojure.java.io :as io])) | |
;;----------------------------------------------------------------------------- | |
(def ^:private path-sep | |
(System/getProperty "path.separator")) | |
(def ^:private class-path | |
(System/getProperty "java.class.path")) | |
(defn- find-this-class | |
[] | |
(->> (str (namespace ::find-this-class) "__init") | |
(namespace-munge) | |
(symbol) | |
(resolve))) | |
;;----------------------------------------------------------------------------- | |
(defn find-jar-file | |
[] | |
(->> (.. (find-this-class) | |
getProtectionDomain | |
getCodeSource | |
getLocation | |
toURI) | |
(io/file) | |
(.getPath))) | |
(defn running-in-jar? | |
[] | |
(try | |
(.endsWith (s/lower-case (find-jar-file)) ".jar") | |
(catch Throwable t false))) | |
(defn clojure-jar | |
[] | |
(->> (-> class-path (s/split (re-pattern path-sep))) | |
(filterv #(.contains % "/clojure-1.")) | |
(first))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment