Recently, I had to put a build timestamp onto a login page for a web application I’m developing at work. The web application is written using Tapestry 4.1, but some of the techniques are equally applicable to other frameworks. I thought I’d share.
First, you need to setup your ant task to grab a timestamp, and put it into your manifest file. You do so using the tstamp task, like this:
The tstamp task is taking the current date and time, formatting it as specified by pattern (just as you’d specify it in a SimpleDateFormat) and placing it in the buildtstamp variable. The manifest task builds a MANIFEST.MF file which ends up in your deployed web application’s META-INF directory. You’ll notice that I’m also putting the name of the user who built the application into the manifest.
Next, we need to read the Manifest from our application. The first screen presented by my Tapestry app is LogOn.java. First, use HiveMind to inject the ServletContext into my page:
Also, we need to create an abstract method into which we’ll store and retrieve the build date:
Finally, we need to read the Manifest file in our pageBeginRender method, and set the “Built On” date accordingly. This is how I did this:
1 2 3 4 5 6 7 8 9 10 11 12
Finally, we need to actually render this on the LogOn page. I did this with a simple Insert component directly on the html page:
And voila! You have a build date on your log page, which can come in handy, e.g., when your QA team doesn’t know which version they’re testing!