This Q came up on the Leiningen list but I wanted to share my answer on the larger Clojure group to get feedback from a bigger pool...
On Mon, Nov 1, 2010 at 8:40 PM, Shantanu Kumar <kumar.shant...@gmail.com> wrote: > There are some resource files (e.g. dbconfig.properties) I need to > include in code so that they are on the classpath. However, they need > to vary during dev/testing and production -- I will have different > versions of dbconfig.properties during dev/testing and production. I > want to know what is the recommended way to include/specify them so > that they are on the classpath based on he profile (dev, testing, > production, staging etc.) I am referring to. FWIW, I've just implemented a system for this which uses a map of maps for configuration and the server's hostname to pick an entry from the environment settings. This is pretty much how I implement it on every project I build (in other languages). The default is 'development'. The settings are dynamically switched at application startup based on the hostname. This allows a single codebase to be used on every server and means I don't have to worry about property files or some such. If you still want per-machine deployment files, you can of course have the environments.clj file dropped in on each machine (equivalent to your dbconfig.properties). I can provide more detail if you'd like but I'll need to do some serious editing since it's fairly specific to our servers / infrastructure :) Here's a taste of the environments.clj file: (def project-environments [ { :name "development-charlie" :hostnames [ "charlieg" ] :settings { :email "char...@domain.com" :dbPassword "mysecret" }} { :name "development-sean" :hostnames [ "Sean-Corfields" "scorfield" ] :settings { :email "s...@corfield.org" :dbPassword "special" }} ... ]) We have an additional wrinkle in that some servers have multiple environments on them in different webroots so our matching code is a little more complex than it would otherwise be based on just the hostname. Here's a taste of the matching code: (defn match-any-host [h n w wp] (and (match-web-root w wp) (if (empty? n) true (some #(match-a-host h %) n)))) (defn find-host [s h w] (let [m (first (filter #(match-any-host h (% :hostnames) w (% :webroot)) s))] (if m (do (println (str "Environment " (m :name) " selected.")) m) (do (println "Environment development defaulted") {:name "development" :settings {}})))) (defn settings [d h] (merge d (h :settings))) (def my-host (find-host worldsingles-environments (hostname) (webroot))) (def my-settings (settings worldsingles-config my-host)) Hope that's useful... -- Sean A Corfield -- (904) 302-SEAN Railo Technologies, Inc. -- http://getrailo.com/ An Architect's View -- http://corfield.org/ "If you're not annoying somebody, you're not really alive." -- Margaret Atwood -- 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