简体   繁体   English

获取leiningen项目根目录

[英]Get leiningen project root directory

How do I get leiningen project's root directory at runtime? 如何在运行时获取leiningen项目的根目录?

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. 我的问题是我想将我的sqlite文件放在根目录下,并通过不同源文件的源代码访问它。

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 : 以下是获取当前工作目录的完整路径的两种方法,当您使用lein repllein run启动Clojure时,它将是项目的主目录:

(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. 在第二种方法中,您可以插入任何路径字符串而不是“。”,如果字符串不包含初始反斜杠,它将相对于Clojure的当前工作目录进行解释。 (I'm not sure whether the behavior is exactly the same on a Windows system.) (我不确定Windows系统上的行为是否完全相同。)

(The first method comes from this question ; the answers there might be useful for your situation.) (第一种方法来自这个问题 ;那里的答案对你的情况可能有用。)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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