Here's what I made quite awhile ago, in case it helps.
http://sidaof.svn.sourceforge.net/viewvc/sidaof/trunk/sidaof-domain/src/main/java/net/sf/sidaof/domain/PomProperties.java?revision=328&view=markup


On Wed, Jan 11, 2012 at 12:27 PM, Matt Walsh
<[email protected]> wrote:
> This is supposed to work, though I haven't tried it personally:
>
> InputStream is =
> this.getClass().getResourceAsStream("/META-INF/MANIFEST.MF")
>
>
>> -----Original Message-----
>> From: Steve Cohen [mailto:[email protected]]
>> Sent: Wednesday, January 11, 2012 11:10 AM
>> To: [email protected]
>> Subject: Re: Howto access project version programmatically within
>> application
>>
>> 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_Vers
>> i
>> > 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:[email protected]]
>> >> Sent: Wednesday, January 11, 2012 10:29 AM
>> >> To: [email protected]
>> >> 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: [email protected]
>> >> For additional commands, e-mail: [email protected]
>> >
>> >
>> >
>> ______________________________________________________________________
>> > 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: [email protected]
>> > For additional commands, e-mail: [email protected]
>> >
>> >
>> >
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>
>
> ______________________________________________________________________
> 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: [email protected]
> For additional commands, e-mail: [email protected]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to