Skip to content

Instantly share code, notes, and snippets.

@zentrope zentrope/utils.clj
Last active Apr 22, 2016

Embed
What would you like to do?
Find out the jar you're running in: Clojure
(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
You can’t perform that action at this time.