This recipe describes how to add build time to a JAR manifest by calling Apache Ant tasks.
Manifest-Version: 1.0 Archiver-Version: Plexus Archiver Created-By: Apache Maven Built-By: vsiveton Build-Jdk: 1.5.0_12 Build-Time: 2008-01-18 06:53:13
To generate and add build time into a Jar Manifest, we are using MANIFEST.MF, located in the src/main/resources/META-INF directory, which contains a built time value to be interpolated, i.e.
Build-Time: ${build.time}
The value ${build.time} from the MANIFEST.MF will be filtering by Maven due to the <filtering> element. The value is taken from the file ${basedir}/target/filter.properties, listed by the <filter> element, i.e.
<resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> <filters> <filter>${basedir}/target/filter.properties</filter> </filters>
The filter.properties file will be generated by the Antrun plugin. We use two core Ant Tasks, <tstamp> and <echo>.
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <phase>generate-resources</phase> <goals> <goal>run</goal> </goals> <configuration> <tasks> <!-- Safety --> <mkdir dir="${project.build.directory}"/> <tstamp> <format property="last.updated" pattern="yyyy-MM-dd hh:mm:ss"/> </tstamp> <echo file="${basedir}/target/filter.properties" message="build.time=${last.updated}"/> </tasks> </configuration> </execution> </executions> </plugin>