Java Version Maven

There are two cases:

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

Steps

  • Make sure the POM contains the configuration for the required plugins described below under "Plugins Needed".
  • There is jar-with-dependencies.xml that is referenced and needs to be put in place. Where is that place?
  • To build the jar, create a launch that looks like this and execute it:
mavenExecutableJar.png
  • The .jar file will end up in the root 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

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>

Assembly Plugin

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.2-beta-2</version>
        <!--   Previous plugin that had been used:
               <artifactId>maven-jar-plugin</artifactId> -->
        <configuration>
 
          <!--  Added to try the assembly -->
          <descriptors>
            <descriptor>
              jar-with-dependencies.xml
            </descriptor>
          </descriptors>
          <!-- Tried different options for this value:
            target: works fine command-line, but m2eclipse adds extra path
            to the front of the paths of expanded classes.
            /: works for both command-line and m2eclipse, but the generated
            .jar file ends up in two different locations; m2eclipse as 
            expected, but command-line puts it in the root of the DOS dir.
            ./: works for both and the .jar ends up in the expected dir.  -->
          <outputDirectory>./</outputDirectory>
          <workDirectory>/target/assembly/work</workDirectory>
 
          <archive>
            <manifest>
              <addDefaultImplementationEntries>
                true
              </addDefaultImplementationEntries>
              <mainClass>
                <!-- Change this to your application's entry point with main() method: -->
                com.jettmarks.base.ArgParsingMain
              </mainClass>
            </manifest>
            <!--  Messes up the rest of this 
              <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>   -->
            <manifestEntries>
              <Implementation-Build>
                ${buildNumber}
              </Implementation-Build>
            </manifestEntries>
          </archive>
 
        </configuration>
      </plugin>
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License