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?
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.)
Can you put the sqlite file in the resources folder and then you could use clojure.java.io/resource to retrieve it at run time?
© 2022 - 2024 — McMap. All rights reserved.
load-file
, although that's not considered a good idea. – Edmondo