How do I get leiningen project's root directory at runtime?
My problem is that I want to place my sqlite file at the root directory, and access it via source code at different source file.
I don't like to use relative path, so how should I do?
Here are two ways to get the full path of the current working directory, which will be the project's home directory when you start Clojure using lein repl
or lein run
:
(System/getProperty "user.dir")
and
(.getCanonicalPath (clojure.java.io/file "."))
In the second method, you can insert any path string instead of ".", and it will be interpreted relative to Clojure's current working directory if the string doesn't contain an initial backslash. (I'm not sure whether the behavior is exactly the same on a Windows system.)
(The first method comes from this question; the answers there might be useful for your situation.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With