- Add build-number plugin to your project main POM
... <build> ... <plugins> ... <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>buildnumber-maven-plugin</artifactId> <version>1.0-beta-3</version> <executions> <execution> <phase>validate</phase> <goals> <goal>create</goal> </goals> </execution> </executions> <configuration> <doCheck>false</doCheck> <doUpdate>false</doUpdate> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-release-plugin</artifactId> <version>2.0</version> </plugin> ... </plugins> ... </build> ... - Change your current jar plugin (or add one if such is missing):
... <plugin> <artifactId>maven-assembly-plugin</artifactId> <version>2.2-beta-2</version> <configuration> <archive> ... <manifest> ... <addDefaultImplementationEntries>true</addDefaultImplementationEntries> ... </manifest> <manifestEntries> <Implementation-Version>${pom.version} (SVN version:${buildNumber})</Implementation-Version> <SVN-Version>${buildNumber}</SVN-Version> </manifestEntries> ... </archive> ... </configuration> <executions> <execution> <goals> <goal>single</goal> </goals> <phase>package</phase> </execution> </executions> </plugin> ... - To get version inside your code use:
public String getVersion() { return <some class inside jar, that is created by maven>.class.getPackage().getImplementationVersion(); }
To get version from running program (server) using only command line:
- Create an JMX interface, with method getVersion() exposed, expose this interface in JMX on host XXX.YYY.ZZZ on port PPP
- Download cmdline-jmxclient utility jar from it's site
- Issue this:
java -jar cmdline-jmxclient-0.10.3.jar a:a XXX.YYY.ZZZ:PPP <name of your JMX bean> Version
Friday, October 29, 2010
Tagging maven build with SVN version, and using this version inside application
To do this, you need to take following steps:
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment