Archive for the ‘ant’ Category

Presentation on Maven

Thursday, February 26th, 2009

Last night I spoke at TechMaine’s Java Users Group about Maven.  I’ve made the slides available on Slideshare, although Slideshare botched some of the formatting a bit.  You will get the proper format if you download it and view it locally.

Enjoy!  Here is the abstract for the presentation if you want to know what it’s about before diving in:

“Why do we need another build tool when we already have Ant? By focusing on convention over configuration, Maven allows you to declaratively define how your project is built, which reduces a lot of the procedural code that you’d need to implement in every build file if you were using Ant. This, along with Maven’s built-in management of repositories for project dependencies, allows you to streamline your build process. Ultimately Maven can reduce the amount of time that would otherwise be wasted hunting down jar files and fiddling with boilerplate build scripts.

This presentation covers Maven’s core concepts. It introduces the Plugin architecture, and explain how the most popular plugins are used. It also covers the POM concept and how it relates to dependency tracking and repositories.”

Build Date on a Tapestry 4 login page using Ant

Thursday, December 13th, 2007

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:

@InjectObject(“service:tapestry.globals.ServletContext”)
public abstract ServletContext getServletContext();

Also, we need to create an abstract method into which we’ll store and retrieve the build date:

public abstract String getBuiltOn();
public abstract void setBuiltOn(String builtOn);

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:

public void pageBeginRender(PageEvent event) {ServletContext sc = this.getServletContext();String filename = sc.getRealPath("/META-INF/MANIFEST.MF");try {  BufferedInputStream i = new BufferedInputStream(new FileInputStream(filename));  Manifest m = new Manifest(i);  Attributes attrib = m.getMainAttributes();  this.setBuiltOn(attrib.getValue("Build-Date"));} catch (Exception e) {  log.warn("Unable to read MANIFEST.MF");}}

Finally, we need to actually render this on the LogOn page. I did this with a simple Insert component directly on the html page:

Built: <span jwcid=”@Insert” value=”ognl:builtOn”>

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!


© 2010 Mike Desjardins. All Rights Reserved.