You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Gunnar Eketrapp <gu...@gmail.com> on 2011/02/01 20:37:38 UTC
Rtrieving version info
How do I access the maven version from my java code.
Re: Rtrieving version info
Posted by Anders Hammar <an...@hammar.net>.
${project.version} is the way to go. ${pom.version} is deprecated.
/Anders
On Tue, Feb 1, 2011 at 22:34, Gunnar Eketrapp <gu...@gmail.com>wrote:
> A java project from within I wanted to access the pom.xml <version> tag.
>
> I found out that I could do this with by filtering my resources and using
> ${pom.version} in my app.properties ...
>
>
> 2011/2/1 Wayne Fay <wa...@gmail.com>
>
> > > How do I access the maven version from my java code.
> >
> > For what purpose, exactly? Are you building a Maven plugin, or simply
> > building some Java project with Maven?
> >
> > Wayne
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> >
> >
>
>
> --
> [Hem: 08-715 59 57, Mobil: 0708-52 62 90]
> Allévägen 2A, 132 42 Saltsjö-Boo
>
Re: Rtrieving version info
Posted by Gunnar Eketrapp <gu...@gmail.com>.
A java project from within I wanted to access the pom.xml <version> tag.
I found out that I could do this with by filtering my resources and using
${pom.version} in my app.properties ...
2011/2/1 Wayne Fay <wa...@gmail.com>
> > How do I access the maven version from my java code.
>
> For what purpose, exactly? Are you building a Maven plugin, or simply
> building some Java project with Maven?
>
> Wayne
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>
--
[Hem: 08-715 59 57, Mobil: 0708-52 62 90]
Allévägen 2A, 132 42 Saltsjö-Boo
Re: Rtrieving version info
Posted by Anders Hammar <an...@hammar.net>.
Unfortunately, this does not work when executing unit tests as the jar has
not been created yet.
/Anders
2011/2/2 Lucas Persson <lu...@oracle.com>
> I can not resist ;-)
> this.getClass().getPackage().getImplementationVersion();
>
> And you need to instruct maven jar plugin to include version info the
> MANIFEST.MF
> E.g.
> <configuration>
> <archive>
> <manifest>
>
> <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
> </manifest>
> </archive>
> </configuration>
> http://maven.apache.org/shared/maven-archiver/index.html
>
> Cheers
> Lucas
>
>
> On 02/02/2011 09:45 AM, Martin Schayna wrote:
>
> On 02/01/2011 10:23 PM, Wayne Fay wrote:
>
> How do I access the maven version from my java code.
>
> For what purpose, exactly? Are you building a Maven plugin, or simply
> building some Java project with Maven?
>
>
> I have done this by reading version number during runtime from MANIFEST.MF
> file:
>
> import java.util.jar.Attributes;
> import java.util.jar.Manifest;
>
> Manifest manifest =
> (Manifest)app.getServletContext().getAttribute("MANIFEST");
> if (manifest == null)
> try {
> manifest = new
> Manifest(app.getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF"));
> } catch (Exception e) {
> manifest = new Manifest();
> }
> String version = getAttribute(manifest, "Implementation-Version");
>
> Just curious if this solution is ok or exists better one?
>
> Thanks, Martin Schayna.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>
> --
> [image: Oracle] <http://www.oracle.com>
> Lucas Persson | Principal Member of Technical Staff
> Phone: +4684773644 <tel:+4684773644> | | | Mobile: +46730946656<tel:+46730946656>
> Oracle Communications Platform
> ORACLE Sweden | Folkungagatan 122 | 116 30 Stockholm
>
> Oracle Svenska AB, Kronborgsgränd 17, S-164 28 KISTA, reg.no. 556254-6746
> [image: Green Oracle] <http://www.oracle.com/commitment> Oracle is
> committed to developing practices and products that help protect the
> environment
>
Re: Rtrieving version info
Posted by Lucas Persson <lu...@oracle.com>.
I can not resist ;-)
this.getClass().getPackage().getImplementationVersion();
And you need to instruct maven jar plugin to include version info the
MANIFEST.MF
E.g.
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
http://maven.apache.org/shared/maven-archiver/index.html
Cheers
Lucas
On 02/02/2011 09:45 AM, Martin Schayna wrote:
> On 02/01/2011 10:23 PM, Wayne Fay wrote:
>>> How do I access the maven version from my java code.
>> For what purpose, exactly? Are you building a Maven plugin, or simply
>> building some Java project with Maven?
>>
>
> I have done this by reading version number during runtime from
> MANIFEST.MF file:
>
> import java.util.jar.Attributes;
> import java.util.jar.Manifest;
>
> Manifest manifest =
> (Manifest)app.getServletContext().getAttribute("MANIFEST");
> if (manifest == null)
> try {
> manifest = new
> Manifest(app.getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF"));
> } catch (Exception e) {
> manifest = new Manifest();
> }
> String version = getAttribute(manifest,
> "Implementation-Version");
>
> Just curious if this solution is ok or exists better one?
>
> Thanks, Martin Schayna.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
--
Oracle <http://www.oracle.com>
Lucas Persson | Principal Member of Technical Staff
Phone: +4684773644 <tel:+4684773644> | | | Mobile: +46730946656
<tel:+46730946656>
Oracle Communications Platform
ORACLE Sweden | Folkungagatan 122 | 116 30 Stockholm
Oracle Svenska AB, Kronborgsgränd 17, S-164 28 KISTA, reg.no. 556254-6746
Green Oracle <http://www.oracle.com/commitment> Oracle is committed to
developing practices and products that help protect the environment
Re: Rtrieving version info
Posted by Martin Schayna <ma...@abra.eu>.
On 02/01/2011 10:23 PM, Wayne Fay wrote:
>> How do I access the maven version from my java code.
> For what purpose, exactly? Are you building a Maven plugin, or simply
> building some Java project with Maven?
>
I have done this by reading version number during runtime from
MANIFEST.MF file:
import java.util.jar.Attributes;
import java.util.jar.Manifest;
Manifest manifest =
(Manifest)app.getServletContext().getAttribute("MANIFEST");
if (manifest == null)
try {
manifest = new
Manifest(app.getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF"));
} catch (Exception e) {
manifest = new Manifest();
}
String version = getAttribute(manifest, "Implementation-Version");
Just curious if this solution is ok or exists better one?
Thanks, Martin Schayna.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: Rtrieving version info
Posted by Wayne Fay <wa...@gmail.com>.
> How do I access the maven version from my java code.
For what purpose, exactly? Are you building a Maven plugin, or simply
building some Java project with Maven?
Wayne
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org