Hi Shahzad,
There is a way to write the project version as a manifest property when
the jar is created by maven.
I saw this example today which would be how to do it:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<index>true</index>
<manifest>
<addDefaultSpecificationEntries>
true
</addDefaultSpecificationEntries>
<addDefaultImplementationEntries>
true
</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Specification-Title>${project.name}</Specification-Title>
<Specification-Version>${project.version}</Specification-Version>
<Implementation-Title>${project.name}</Implementation-Title>
<Implementation-Version>${project.version} ${buildNumber} -
${user.name}</Implementation-Version>
<SCM-Revision>${buildNumber}</SCM-Revision>
<SCM-url>${scm.url}</SCM-url>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
Checkout the SpringVersion class on how you can access the
Implementation-Version manifest property inside your code:
public class SpringVersion {
/**
* Return the full version string of the present Spring codebase,
* or <code>null</code> if it cannot be determined.
* @see java.lang.Package#getImplementationVersion()
*/
public static String getVersion() {
Package pkg = SpringVersion.class.getPackage();
return (pkg != null ? pkg.getImplementationVersion() : null);
}
}
Hope this is useful for you,
Regards,
Mike
Hi all,
I would like the ability to read the project's version number from pom in my
java code as I need to insert that version number in the text file I generate
as a result of my code. I am NOT writing a maven plugin but a standalone java
project that uses maven as a build/dependency system
At this point, I can only think of one way of doing that and that is using the
properties-maven-plugin to output the<properties> section from the pom into a text
file and in my<properties> seciton I reference the project's version as
${project.version}
Can you suggest or think of a better solution?
thanks
--------------------------------------------
Shahzad Qureshi
Systems Analyst/Programmer
Applications Directorate | La direction générale des applications
Chief Information Officer Branch | Direction générale du dirigeant principal de
l'information
Environment Canada | Environnement Canada
[email protected]
Telephone | Téléphone 416-739-4702
Government of Canada | Gouvernement du Canada
Website | Site Web www.ec.gc.ca
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]