Cookbook: How To Add Build Time To A JAR Manifest?


This recipe describes how to add build time to a JAR manifest by calling Apache Ant tasks.

Prerequisite Plugins

Here is the list of the plugins used:

Plugin Version
antrun 1.1
jar 2.2

Sample Generated Manifest

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


Configuring MANIFEST.MF

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}

Configuring The POM

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/, listed by the <filter> element, i.e.



Configuring Maven Antrun Plugin

The file will be generated by the Antrun plugin. We use two core Ant Tasks, <tstamp> and <echo>.

                <!-- Safety -->
                <mkdir dir="${}"/>

                  <format property="last.updated" pattern="yyyy-MM-dd hh:mm:ss"/>
                <echo file="${basedir}/target/" message="build.time=${last.updated}"/>

Configuring Maven Jar Plugin

The last configuration is to set the defaultManifestFile to true to enable it.


Running Maven

Just call Maven to generate the package:

mvn package

Other Tips

You could tweak the Jar Plugin configuration into the War Plugin.