Creating an ear with version for Weblogic using Maven
Using the ear plugin of Maven 2 creating an ear is very easy. The produced ear follows the JEE spec, so you can normally use it in any application server.
I'm using the ear plugin as well, in my case to be used for Weblogic 9. Weblogic has a feature that allows you to update applications on the fly using the Deployments, update command. However, to be able to use that feature well, the MANIFEST file of the ear has to include a Weblogic specific version field called WebLogic-Application-Version, with a unique version for each ear you'd want to include. Without the version number, Weblogic will list the application twice in the weblogic administration console.
Adding a custom manifest entry is quite easy. Just add an entry to the configuration of the Maven 2 ear plugin, as shown in the example below:
<plugin> <artifactId>maven-ear-plugin</artifactId> <configuration> <archive> <manifestEntries> <WebLogic-Application-Version>${project.version}</WebLogic-Application-Version> </manifestEntries> </archive> ... </plugin>
This will cause the Manifest file to contain an entry WebLogic-Application-Version containing the current version of your Maven project.
However, this wasn't enough for me: I'm sometimes modifying and recreating the ear multiple times per day during development. The maven project version remains the same, which means Weblogic won't see my new development ear as a new version.
The solution is to include a timestamp in the version as well. By default, Maven doesn't include a timestamp. Fortunately there's Stackoverflow with the answer: there's an external plugin called buildnumber-maven-plugin that allows you do that.
For my weblogic specific entry I added the following to the pom.xml file:
<groupId>org.codehaus.mojo</groupId> <artifactId>buildnumber-maven-plugin</artifactId> <version>1.0-beta-3</version> <configuration> <format>{0,date,yyyyMMddHHmmss}</format> <items> <item>timestamp</item> </items> </configuration> <executions> <execution> <phase>validate</phase> <goals> <goal>create</goal> </goals> </execution> </executions> </plugin>
The above entry will make a variable buildNumber available during build containing a timestamp.
The maven ear configuration becomes:
<plugin> <artifactId>maven-ear-plugin</artifactId> <configuration> <archive> <manifestEntries> <!-- Buildnumber property is generated by buildnumber-maven-plugin, see above --> <WebLogic-Application-Version>${project.version}_${buildNumber}</WebLogic-Application-Version> </manifestEntries> </archive> ... </plugin>
After installation in Weblogic using the admin console, weblogic now lists the version number, date and time after I install my ear. Upgrading the application won't result in two applications being listed.