Skip to content

Instantly share code, notes, and snippets.

@ghoseb ghoseb/props.clj
Last active Dec 12, 2015

What would you like to do?
Read a Java Properties file into a map (with potentially nested keys).
(ns ^{:doc "Read Java properties file."
:author "Baishampayan Ghose <>"}
(:import java.util.Properties)
(:require [ :refer [resource reader]]
[clojure.string :refer [split]]))
(defn- load-props
"Load a Java properties file. File should be in classpath."
(doto (Properties.)
(.load (-> props-file resource reader))))
(defn- key->path
(map keyword (split k #"\.")))
(defn read-props
"Read a Java properties file into a map."
(let [props (load-props props-file)]
(reduce (fn [res k]
(assoc-in res (key->path k) (get props k)))
(keys props))))
name = configuration-clj
version = 0.2.4 = whacko-db =
db.port = 4567
ring.handler.ns = some-ring-handler-ns
ring.handler.protocol = binary
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.