【发布时间】:2010-05-01 18:13:52
【问题描述】:
Clojure 程序如何找到自己的 MANIFEST.MF(假设它被打包在 JAR 文件中)。
我正在尝试从我的“-main”函数中执行此操作,但在以下代码中找不到要使用的类:
(.getValue
(..
(java.util.jar.Manifest.
(.openStream
(java.net.URL.
(str
"jar:"
(..
(class **WHAT-GOES-HERE**)
getProtectionDomain
getCodeSource
getLocation)
"!/META-INF/MANIFEST.MF"))))
getMainAttributes)
"Build-number"))
谢谢。
【问题讨论】:
-
谢谢,这很有帮助。我做了一些重构,因为我对此很着迷。这是我最终得到的结果: (defn get-function-location [sym] (.. (class sym) getProtectionDomain getCodeSource getLocation)) (defn get-manifest-attributes [] (let [location (get-function-location get- manifest-attributes)] (when-not (nil? location) (-> (str "jar:" location "!/META-INF/MANIFEST.MF") (URL.) (.openStream) (Manifest.) (. getMainAttributes)))))
-
更正:将符号传递给函数无法正常工作。我最终将 get-function-location 重命名为 get-location 并将 get-location 传递给类。