Can't help much.
I don't have an elegant way either.

Here is what I did use for long time to get a value from a manifest file inside a jar:
(it is still poor, but served the purpose.)
(stripped all error handling and specific clutter from application)

    final String path = "jar:"
+ SomeWellKnownClassFromYourApplicationJar.class.getProtectionDomain().getCodeSource().getLocation().toString()
                                + "!/META-INF/MANIFEST.MF";
    final InputStream in = new URL(path).openStream();
    if (in != null) {
            mf = new Manifest(in);
            if (mf != null) {
if (mf.getMainAttributes().getValue(VERSION_TAG) != null) { return mf.getMainAttributes().getValue(VERSION_TAG);
                    }
           }
   }

But I remember you said something about you could not use protected methods....
so this might not work for you....

Sorry
Rainer

On 11.01.2012 19:10, Steve Cohen wrote:
Hmm, intriguing but not working in my case which is a jar, not a war or ear. This is standalone java app.

I've tried
getResourceAsStream("META_INF/MANIFEST.MF") and
getResourceAsStream("/META_INF/MANIFEST.MF") without success even though I've verified that the file exists in the jar,

How does one read the manifest from an executable jar?


On 01/11/2012 11:35 AM, Matt Walsh wrote:
This is referenced from the maven-buildnumber-plugin documentation.

http://apollo.ucalgary.ca/tlcprojectswiki/index.php/Public/Project_Versi
oning_-_Best_Practices#Build_Versioning

Where they do the following (assuming, of course, you've placed the info
in your manifest file):


String appServerHome = getServletContext().getRealPath("/");

File manifestFile = new File(appServerHome, "META-INF/MANIFEST.MF");

Manifest mf = new Manifest();
mf.read(new FileInputStream(manifestFile));

Attributes atts = mf.getMainAttributes();

System.out.println("Version: " +
atts.getValue("Implementation-Version"));
System.out.println("Build: " + atts.getValue("Implementation-Build"));

-----Original Message-----
From: Steve Cohen [mailto:sco...@javactivity.org]
Sent: Wednesday, January 11, 2012 10:29 AM
To: users@maven.apache.org
Subject: Re: Howto access project version programmatically within
application

On 01/11/2012 10:50 AM, Stephen Connolly wrote:

getClass().getClassLoader().getPackage("").getImplementationVersion()


I really liked the simplicity of this idea.  Alas,
ClassLoader.getPackage(String) is a protected method, so this won't
help.

Accessible to me is:

Package.getPackage("").getImplementationVersion(), which according to
Javadocs sounds like it would do the same thing, but this throws a
NullPointerException.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@maven.apache.org
For additional commands, e-mail: users-h...@maven.apache.org


______________________________________________________________________
This message, including any attachments, is confidential and contains information intended only for the person(s) named above. Any other distribution, copying or disclosure is strictly prohibited. If you are not the intended recipient or have received this message in error, please notify us immediately by reply email and permanently delete the original transmission from all of your systems and hard drives, including any attachments, without making a copy.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@maven.apache.org
For additional commands, e-mail: users-h...@maven.apache.org





---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@maven.apache.org
For additional commands, e-mail: users-h...@maven.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@maven.apache.org
For additional commands, e-mail: users-h...@maven.apache.org

Reply via email to