RSS Feed for This PostCurrent Article

Maven: Adding Custom Attributes and Build Timestamp to Manifest

Here is how I add custom attributes and build time stamp to my manifest file. Reference is made to the Maven CookBook.

First, in src/main/resources/META-INF/MANIFEST.MF, I added the following entries

Specification-Title: App Name
Specification-Version: ${pom.version} - ${build.time}
Specification-Vendor: Company Name
Implementation-Title: App Name
Implementation-Version: ${pom.version} - ${build.time}
Implementation-Vendor: Company Name
Built-By: ${user.name}
Build-Jdk: ${java.version}
Build-Time: ${build.time}

In my pom.xml file, I added the following

<resources>
  <resource>
    <directory>src/main/resources</directory>
    <filtering>true</filtering>
  </resource>
</resources>

<filters>
  <filter>${basedir}/target/filter.properties</filter>
</filters>

I use Maven AntRun plugin to generate the build time,

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
  <execution>
    <phase>generate-resources</phase>
    <goals>
      <goal>run</goal>
    </goals>
    <configuration>
      <tasks>
        <mkdir dir="${project.build.directory}"/>
        <tstamp>
          <format property="last.updated" 
            pattern="yyyy-MM-dd hh:mm:ss"/>
        </tstamp>
        <echo file="${basedir}/target/
    filter.properties" message="build.time=${last.updated}"/>
      </tasks>
    </configuration>
  </execution>
</executions>
</plugin>

Then I set the pom file to use the default manifest file

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.2</version>
    <configuration>

        <useDefaultManifestFile>true</useDefaultManifestFile>

        <!--
        <archive>
            <index>true</index>
                <manifest>
                <addClasspath>true</addClasspath>
                <addDefaultImplementationEntries>true
                </addDefaultImplementationEntries>
                <addDefaultSpecificationEntries>true&
                lt;/addDefaultSpecificationEntries>
            </manifest>

            <manifestEntries>             
                <Built-By>${user.name}</Built-By>
                <Build-Jdk>${java.version}</Build-Jdk>
            </manifestEntries>
        </archive>
        -->
    </configuration>

</plugin>

Then generated MANIFEST.MF in the jar file will look like this.

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: admin
Build-Jdk: 1.5.0_14
Specification-Title: App Name
Specification-Version: 0.1 - 2008-02-21 01:03:13
Specification-Vendor: Company Name
Implementation-Title: App Name
Implementation-Version: 0.1 - 2008-02-21 01:03:13
Implementation-Vendor: Company Name
Build-Time: 2008-02-21 01:03:13


Trackback URL


RSS Feed for This Post1 Comment(s)

  1. James | Feb 5, 2009 | Reply

    I couldn’t get this to work with the war plugin instead of the jar. Is there something different you have to do with war plugins?

    I am using mvn 2.0.9 with the

    maven-war-plugin
    2.1-alpha-1

1 Trackback(s)

  1. From Maven: Añadiendo el Timestamp al número de versión « El Blog de rubensa | Apr 15, 2009

Sorry, comments for this entry are closed at this time.