下面是我从 REPL(在Light Table中)运行的代码,我目前对此感到困惑。
这似乎工作正常:
(require '[clojure.java.classpath :as classpath])
(import '[java.io File])
(map #(File. (.toURI %))
(classpath/classpath))
结果:
(#<File C:\Documents%20and%20Settings\Kenny\My%20Documents\hello-heroku-clojure-world\test>
#<File C:\Documents%20and%20Settings\Kenny\My%20Documents\hello-heroku-clojure-world\src>
#<File C:\Documents%20and%20Settings\Kenny\My%20Documents\hello-heroku-clojure-world\dev-resources>
#<File C:\Documents%20and%20Settings\Kenny\My%20Documents\hello-heroku-clojure-world\resources>
#<File C:\Documents%20and%20Settings\Kenny\My%20Documents\hello-heroku-clojure-world\target\classes>
...
但是以下似乎表明所有文件都不是目录:
(filter #(.isDirectory (File. (.toURI %)))
(classpath/classpath))
结果:
()
编辑- 我很确定以下是我感到困惑的代码的更简单版本;它产生相同的结果:
(filter #(.isDirectory %)
(classpath/classpath))
但是,这似乎有效:
(filter #(.isDirectory (File. (URLDecoder/decode (.getPath %))))
(classpath/classpath))
结果:
(#<File C:\Documents%20and%20Settings\Kenny\My%20Documents\hello-heroku-clojure-world\test>
#<File C:\Documents%20and%20Settings\Kenny\My%20Documents\hello-heroku-clojure-world\src>
#<File C:\Documents%20and%20Settings\Kenny\My%20Documents\hello-heroku-clojure-world\resources>
#<File C:\Documents%20and%20Settings\Kenny\My%20Documents\hello-heroku-clojure-world\target\classes>)
[我的类路径中的所有其他文件都是 JAR 文件。]
编辑——我在 Windows XP 上运行它。
编辑——这肯定是路径和空间的问题;我运行了以下内容:
(filter #(.exists %)
(classpath/classpath))
结果:
()
相关代码来自clojure.java.classpath
:
(defn loader-classpath
"Returns a sequence of File paths from a classloader."
[loader]
(when (instance? java.net.URLClassLoader loader)
(map io/as-file (.getURLs ^java.net.URLClassLoader loader))))