Wednesday, May 7, 2008

How to present the version number on a web front end with spring and maven

Blink It Digg! Dzone

This bog will describe how to present a application version number in
the pom.xml on a web front end by using spring and maven. Maven
generates by default a pom.properties file in the META-INF folder when
generating a war. This file holds the following fields; version,
groupId, artifactId

The exact location from your context root is;

META-INF/maven/<groupId>/<artifactId>/pom.properties


by specifying the following bean in your spring config; (REPLACE
<groupId> and <artifactId> with what you have defined in your pom.xml)

<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
>
<property name="basenames">
<list>
<value>META-INF/maven/<groupId>/<artifactId>/pom</value>
</list>
</property>
</bean>


Now the properties in this file can be used in your font-end by using
the standard spring tags for example to print the version number in a
jsp file use the following line;

<b>Version:</b> <spring:message code="version"/>


REMARK don't forget to add the spring tag definition to your jsp file;

<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>