简体   繁体   中英

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?

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

你可以把sqlite文件放在resources文件夹中然后你可以使用clojure.java.io/resource在运行时检索它吗?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM