blob: 2e10f918189736611aaa8a9139d46e9b1d2beb14 [file] [log] [blame]
-----
Cookbook - How To Add Build Time To A JAR Manifest
-----
Vincent Siveton
-----
2008-01-01
-----
~~ Licensed to the Apache Software Foundation (ASF) under one
~~ or more contributor license agreements. See the NOTICE file
~~ distributed with this work for additional information
~~ regarding copyright ownership. The ASF licenses this file
~~ to you under the Apache License, Version 2.0 (the
~~ "License"); you may not use this file except in compliance
~~ with the License. You may obtain a copy of the License at
~~
~~ http://www.apache.org/licenses/LICENSE-2.0
~~
~~ Unless required by applicable law or agreed to in writing,
~~ software distributed under the License is distributed on an
~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~~ KIND, either express or implied. See the License for the
~~ specific language governing permissions and limitations
~~ under the License.
~~ NOTE: For help with the syntax of this file, see:
~~ http://maven.apache.org/doxia/references/apt-format.html
Cookbook: How To Add Build Time To A JAR Manifest?
* Summary
This recipe describes how to add build time to a JAR manifest by calling {{{http://ant.apache.org}Apache Ant}} tasks.
* Prerequisite Plugins
Here is the list of the plugins used:
*-----------------------------------------------------------+--------------+
|| <<Plugin>> || <<Version>>
*-----------------------------------------------------------+--------------+
| {{{../../plugins/maven-antrun-plugin/} <<<antrun>>>}} | 1.1
*-----------------------------------------------------------+--------------+
| {{{../../plugins/maven-jar-plugin/} <<<jar>>>}} | 2.2
*-----------------------------------------------------------+--------------+
* Sample Generated Manifest
+-----+
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: vsiveton
Build-Jdk: 1.5.0_12
Build-Time: 2008-01-18 06:53:13
+-----+
* Recipe
** Configuring MANIFEST.MF
To generate and add build time into a Jar Manifest, we are using <<<MANIFEST.MF>>>, located in the <<<src/main/resources/META-INF>>> directory,
which contains a built time value to be interpolated, i.e.
+-----+
Build-Time: ${build.time}
+-----+
** Configuring The POM
The value $\{build.time\} from the <<<MANIFEST.MF>>> will be filtering by Maven due to the \<filtering\> element.
The value is taken from the file <<<$\{basedir\}/target/filter.properties>>>, listed by the \<filter\> element, i.e.
%{snippet|id=pom|url=https://svn.apache.org/repos/asf/maven/sandbox/trunk/site/cookbook/generate-build-time/pom.xml}
** Configuring Maven Antrun Plugin
The <<<filter.properties>>> file will be generated by the Antrun plugin. We use two core Ant Tasks,
{{{http://ant.apache.org/manual/CoreTasks/tstamp.html}\<tstamp\>}} and
{{{http://ant.apache.org/manual/CoreTasks/echo.html}\<echo\>}}.
%{snippet|id=antrun|url=https://svn.apache.org/repos/asf/maven/sandbox/trunk/site/cookbook/generate-build-time/pom.xml}
** Configuring Maven Jar Plugin
The last configuration is to set the <<<defaultManifestFile>>> to <<<true>>> to enable it.
%{snippet|id=jar|url=https://svn.apache.org/repos/asf/maven/sandbox/trunk/site/cookbook/generate-build-time/pom.xml}
** Running Maven
Just call Maven to generate the package:
+-----+
mvn package
+-----+
* Other Tips
You could tweak the Jar Plugin configuration into the War Plugin.
* Resources
* Source code: {{{https://svn.apache.org/repos/asf/maven/sandbox/trunk/site/cookbook/generate-build-time}https://svn.apache.org/repos/asf/maven/sandbox/trunk/site/cookbook/generate-build-time}}
* {{{../../plugins/maven-antrun-plugin/} Maven Antrun Plugin}}
* {{{../../plugins/maven-jar-plugin/} Maven Jar Plugin}}
[]