Crossposted to StackoverFlow.

How can a Clojure program find its own MANIFEST.MF (assuming it is
packaged in a JAR file).

I am trying to do this from my "-main" function, but I can't find a
class to use in the following code:

  (.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"))

I have found an answer that works, however I am open to suggestions
for improving it, particularly replacing the call to Class/forName.

(defn -main [& args]
  (println "Version "
    (.getValue
      (..
        (Manifest.
          (.openStream
            (URL.
              (str
                "jar:"
                (..
                  (Class/forName "org.example.myproject.thisfile")
                  getProtectionDomain
                  getCodeSource
                  getLocation)
                "!/META-INF/MANIFEST.MF"))))
        getMainAttributes)
      "Build-number")))

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to