Java Version Maven War

There are two cases:

  1. Java Version within the Manifest for a standalone Executable Jar. That is described under Java Version Maven.
  2. Java Version within the Manifest for a WAR file. That is shown below.

Steps

  • Make sure the POM contains the configuration for the required plugins described below under "Plugins Needed".
  • The .war file will end up under the /target directory of the project. Open it with WinZip? and look for the Manifest.mf file.
  • Inside the Manifest.mf, you should see the following lines (with information specific to your app):
Manifest-Version: 1.0
      Archiver-Version: Plexus Archiver
      Created-By: Apache Maven
      Built-By: blmdqwc
      Build-Jdk: 1.6.0_04
      Implementation-Title: UserHelperGUI
      Implementation-Version: 0.0.1-SNAPSHOT
      Implementation-Vendor-Id: com.att.eum.pss
      Main-Class: com.att.eum.pss.uh.UserHelperGUI
      Implementation-Build: 4@2009/07/15 15:04:29
  • To retrieve the build information, you can use the ManifestVersion class.

Plugins Needed

Most POMs created from an archetype will not have the plugins or plugin management required to support embedding the version information inside of the Manifest of a jar file as recommended by Sun. This shows the plugins and Plugin Management required.

javaVersionMavenPlugins.png
  • These are the configurations needed for each of the sections. All of the XML below is contained within the <build> section.

Plugin Management

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

Plugin for compiler

    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.5</source>
          <target>1.5</target>
        </configuration>
      </plugin>

Plugin Buildnumber

      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>buildnumber-maven-plugin</artifactId>
        <version>1.0-beta-3</version>
        <executions>
          <execution>
            <phase>validate</phase>
            <goals>
              <goal>create</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <format>
            {0,number}@{1,date,yyyy/MM/dd HH:mm:ss}
          </format>
          <items>
            <item>buildNumber0</item>
            <item>timestamp</item>
          </items>
        </configuration>
      </plugin>

WAR Plugin

        <configuration>
          <archive>
            <manifest>
              <addDefaultImplementationEntries>
                true
              </addDefaultImplementationEntries>
            </manifest>
            <manifestEntries>
              <Implementation-Build>
                ${buildNumber}
              </Implementation-Build>
            </manifestEntries>
          </archive>
        </configuration>
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License