Hello,

What is the best way to read a property file in a path independent
way? I would like to be able to read the file and this regardless of
where my clojure program is called from (this must also work if my
program is bundled as a jar).

clojure.contrib.java-utils/read-properties is nice but it takes a
file, how could a relative file be expressed relatively to a namespace
name, project root directory or relatively to a clojure file?

I did try with ClassLoader/getSystemResourceAsStream :

(defn- read-properties
 "Read properties from filename. Filename is searched in the
classpath"
   ;; see also clojure.contrib.java-utils
   [filename]
   (with-open [b (ClassLoader/getSystemResourceAsStream filename)]
     (doto (java.util.Properties.)
       (.load b))))

It works fine and you can specify a filename relatively to a namespace
like this : "namespace/myconfig.properties".

However this breaks with "lein swank" since lein swank uses its own
classloader.

What is the best solution?

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to