CompilerException java.io.FileNotFoundException: *** (The system cannot find the file specified)

While creating a configuration file in clojure project, i ran with some errors which i think would be common for beginners.

usually the project structure in clojure is
     myapp/src/myapp/*.clj

In one of my clj file, i wanted to load a configuration file and read properties from it.

I used the given code from stack-overflow and it looks like :

(defn load-props [file-name]
  (with-open [^java.io.Reader reader (clojure.java.io/reader file-name)] 
    (let [props (java.util.Properties.)]
      (.load props reader)
      (into {} (for [[k v] props] [(keyword k) (read-string v)])))))



so to load a property file i did

(def properties (load-props "myconf.conf"))


Running it i got :
 
CompilerException java.io.FileNotFoundException: myconf.conf (The system cannot find the file specified)


The runtime try to find file with respect to the root of the project folder so the path should be :

  "src/myapp/myconf.conf"

i.e.

(def properties (load-props "src/myapp/myconf.conf"))

and it worked.

My configuration file was like this :

{
        :key  "mysecretkey"
}


and it started giving me error :

CompilerException java.lang.RuntimeException: EOF while reading, compiling:(form-init6711585374647917408.clj:1:8) 

I change the conf file to simple file as

key:  "mysecretkey"

hello : "sowhat"

myarr : ["so" "good"]


and IT WORKED :)

giving
{:hello "sowhat", :key "mysecretkey", :myarr ["so" "good"]}


Comments