The Holy Java

Building the right thing, building it right, fast

Ant/Maven: Add build date/revision to the generated JAR’s Manifest

Posted by Jakub Holý on October 19, 2006

I’ll explain how to get build time info and svn revision into the buildedjar/ear in Maven or Ant.

1. Maven

If you want to have the build date of a JAR built by Maven in its Manifest
file, paste the following lines at the beginning of your maven.xml:

<j:set value="JarBuildDate var="maven.jar.manifest.attributes.list" />
<j:set value="${DSTAMP}" var="maven.jar.manifest.attribute.JarBuildDate" />


  1. <tstamp/> executes the Ant’s task Tstamp, which
    defines the variables DSTAMP (date in the form YYYYMMDD), TODAY (MMMM dd
    yyyy) and TSTAMP (hhmm).
  2. The property maven.jar.manifest.attributes.list tells the
    jar:jar goal what entries to add into the resulting manifest. Attention:
    value=”JarBuildDate” and =” JarBuildDate” define 2 different variables,
    i.e. whitespaces are very significant. You must also comply with the
    definition of valid manifest entriy names. The variable may hold multiple
    entries separated by a comma. Side note: what happens, if the variable is
    already set? Is the old value preserved or overwritten?
  3. maven.jar.manifest.attribute.JarBuildDate sets the value
    for the manifest entry defined in the …list property.

2. Ant

<!-- Create manifest with build time info -->
<manifest file="ear-MANIFEST.MF">
                 <attribute name="MyBuild-Date" value="${DSTAMP}" />
                 <attribute name="MyBuild-Time" value="${TSTAMP}" />
                 <attribute name="MyBuild-Svn-Revision" value="${svn.version}" />

<jar manifest="ear-MANIFEST.MF" .. /> <!-- the same for an <ear .. -->

Explanation: It’s basically the same as for maven. The task ‘manifest’
generates a manifest file.

3. Get SVN revision

Warning:This only works with the plain-text format of .svn/entries, not with the older XML format.

To get an SVN revision of you project at the time of building, you can use
the following task to get the revision number into the property svn.version
(requires ant >= 1.6):

   property="svn.version" srcFile=".svn/entries" failonerror="true">
      <headfilter lines="6"/>
         <replaceregex pattern=".*[\r\n]+dir[\r\n]+([0-9]+)[\r\n]+http://.*"
            flags="s" replace="\1"/>

.svn/entries is a SVN file having something like this somewhere at its


  • headfilter takes first 6 lines of the file
  • filetokenizer gets all those lines into 1 string
  • replaceregexp finds the revision number in it and replaces
    all the string with this number
  • the result is stored into the property svn.version

2 Responses to “Ant/Maven: Add build date/revision to the generated JAR’s Manifest”

  1. dan oxlade said

    thanks this helped me out, although small note: you should change the reg-exp to https if your svn server is https, or better still modify the reg-exp to take either.

  2. LuVar said

    Hi. Imho much cleaner is not to grep info from some svn files, but to retrive it from svn program. Example ussage is here:

Sorry, the comment form is closed at this time.

%d bloggers like this: