1) Add version bean in you context
<bean id="version" class="com.real.ecs.common.version.Version" init-method="init">
<property name="buildVersion"><value>${build.version}</value></property>
<property name="buildTime"><value>${build.time}</value></property>
<property name="buildUser"><value>${build.user}</value></property>
</bean>
2) Add build-version.properties in your classpath
build.version=${maven.build.version}
build.user=${maven.build.user}
build.time=${maven.build.time}
3. Add propertyConfigure to set your property valid.
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:build-version.properties</value>
</list>
</property>
</bean>
4. Add version servlet in your web.xml
<servlet>
<servlet-name>version</servlet-name>
<servlet-class>
com.real.ecs.common.version.VersionServlet
</servlet-class>
<load-on-startup>4</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>version</servlet-name>
<url-pattern>/version</url-pattern>
</servlet-mapping>
5. Add maven ant plugin in build section of your pom file to create filter
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>create-filter</id>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<!-- Generate filter file -->
<tstamp>
<format property="timestamp" pattern="MM/dd/yyyy hh:mm:ss" />
</tstamp>
<condition property="username" value="UNKNOWN">
<not>
<isset property="username" />
</not>
</condition>
<condition property="tag" value="UNKNOWN">
<not>
<isset property="tag" />
</not>
</condition>
<property name="nl" value="
" />
<mkdir dir="${basedir}/target" />
<echo file="${basedir}/target/filter.properties" message="maven.build.version=${pom.version}" append="true" />
<echo file="${basedir}/target/filter.properties" message="${nl}" append="true" />
<echo file="${basedir}/target/filter.properties" message="maven.build.user=${username}" append="true" />
<echo file="${basedir}/target/filter.properties" message="${nl}" append="true" />
<echo file="${basedir}/target/filter.properties" message="maven.build.time=${timestamp}" append="true" />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
6) add filter and resource in build section of pom to set the version, user and time for your property file in build phase.
<filters>
<filter>${basedir}/target/filter.properties</filter>
</filters>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/build-version.properties</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>**/build-version.properties</exclude>
</excludes>
<filtering>false</filtering>
</resource>
</resources>