16 November 2008

How to add entries in MANIFEST.MF using Maven in WAR

We may come across a situation where we need to add more entries to MANIFEST.MF in jar or war files other than the default entries. In Maven we have plug ins to accomplish the same.

In war files, we can use maven-war-plugin as below. Build number and the computer name will be added along with the default entries.
       <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.0.2</version>
        <configuration>
          <manifest>
            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
          </manifest>
          <archive>
            <manifestEntries>
              <Implementation-Build>${buildNumber}</Implementation-Build>
              <Build-Machine>${env.COMPUTERNAME}</Build-Machine>
            </manifestEntries>
          </archive>
        </configuration>
      </plugin>

</plugins>
   </build>

In EJB jar files we can use maven-ejb-plugin. For normal jars please use maven-jar-plugin in a similar fashion

 <plugin>
            <artifactId>maven-ejb-plugin</artifactId>
            <configuration>
               <archive>
                  <manifest>
                     <addClasspath>true</addClasspath>
                  </manifest>
                   <manifestEntries>
              <Implementation-Build>${buildNumber}</Implementation-Build>
              <Build-Machine>${env.COMPUTERNAME}</Build-Machine>
            </manifestEntries>
               </archive>
            </configuration>
         </plugin>