20

If I want to embed the current time in JAR manifest using ant is there an ant property I can use for "now" and which manifest attribute is the best to put this information?

I currently have the following

  <manifest>
    <attribute name="Signature-Title" value="${project.name}"/>
    <attribute name="Signature-Version" value="${release.version}"/>
    <attribute name="Signature-Vendor" value="XXX"/>
    <attribute name="Built-By" value="${user.name}"/>
  </manifest>
Mike Q
  • 22,839
  • 20
  • 87
  • 129

2 Answers2

24

You can use the tstamp task for this.

 <tstamp>
    <format property="TODAY" pattern="yyyy-MM-dd HH:mm:ss" />
  </tstamp>

  <manifest>
    <attribute name="Signature-Title" value="${project.name}"/>
    <attribute name="Signature-Version" value="${release.version}"/>
    <attribute name="Signature-Vendor" value="XXX"/>
    <attribute name="Built-By" value="${user.name}"/>
    <attribute name="Built-Date" value="${TODAY}"/>
  </manifest>

This task set three properties (DSTAMP, TSTAMP, and TODAY) with the current timestamp, each in a different default format (check the link). With the nested format node, you can define a custom format for any of them.

Tomas Narros
  • 13,390
  • 2
  • 40
  • 56
  • It's worth noting that embedding the built time in the MANIFEST will cause the WAR to be rebuilt _every time_ even if nothing at all has changed; not very clean IMO. – Marcus Junius Brutus Mar 07 '19 at 19:11
0

Use UTC format only in jaror war META-INF/MANIFEST.MF (don't use localized date/time without TZ because you will lost TimeZone information).

See How to have Maven show local timezone in maven.build.timestamp?

Míra
  • 1,465
  • 16
  • 13