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"))
Run Code Online (Sandbox Code Playgroud)
谢谢.
这似乎工作可靠:
(defn set-version
"Set the version variable to the build number."
[]
(def version
(.getValue (.. (Manifest.
(.openStream
(URL.
(str "jar:"
(.getLocation
(.getCodeSource
(.getProtectionDomain org.example.myproject.thisfile)))
"!/META-INF/MANIFEST.MF"))))
getMainAttributes)
"Build-number")))
Run Code Online (Sandbox Code Playgroud)