Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get leiningen project root directory

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?

like image 881
user2925565 Avatar asked Oct 14 '14 10:10

user2925565


1 Answers

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.)

like image 61
Mars Avatar answered Sep 28 '22 02:09

Mars