Pages

Monday, October 28, 2013

Bundling single or multiple ear using assembly plug-in - How to use maven dependency set

Our application consists of multiple EAR's online, batch etc.
We faced a situation where we need to bundle multiple ear's, db scripts and property
files to make a delivery. I searched for creating an assembly descriptor but could not
find exact details on how to do it. After couple of days of browsing and trial and
error I figured out a way.

For example your application contains appl-1-ear (version - 1.0),appl-2-ear (version 2.0),
db-scripts.zip (0.0.1), properties.zip (0.0.10). You need to create a pom file which contains the
versions you want to include in your final delivery.

The advantage of this approach is, you can deliver your compoents and just declare the versions in
your delivery pom to create a final delivery. Even if it is not multiple ear's, but you have to
bundle various versions of db scripts with different versions of application this approach will
come handy.

You need to create a pom file something like below. Here declaring the type as ear is important because
by default maven searches for Jar extension for the given version number.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.ravi</groupId>
    <artifactId>appl-delivery</artifactId>
    <version>0.0.2-SNAPSHOT</version>
    <packaging>pom</packaging>
<dependencies>
    <dependency>
<groupId>com.ravi.presentation</groupId>
<artifactId>appl-1-ear</artifactId>
<version>1.o</version>
<type>ear</type>
    </dependency>
   <dependency>
<groupId>com.ravi.batch</groupId>
<artifactId>appl-2-ear</artifactId>
<version>1.0</version>
<type>ear</type>
    </dependency>
<dependency>
<groupId>com.ravi.properties</groupId>
<artifactId>properties</artifactId>
<version>0.0.10</version>
<classifier>archive</classifier>
<type>zip</type>
</dependency>
<dependency>
<groupId>com.ravi.dbscripts</groupId>
<artifactId>db-scripts</artifactId>
<version>0.0.1</version>
<classifier>archive</classifier>
<type>zip</type>
</dependency>
  </dependencies>
 <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.2-beta-2</version>
                <executions>
                    <execution>
                        <id>bundle-project-sources</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptors>
<descriptor>assembly.xml</descriptor>
 </descriptors>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

your assembly descriptor will look something like this

<assembly>
    <id>archive</id>
    <formats>
        <format>tar.gz</format>
    </formats>
    <dependencySets>
    <dependencySet>
        <includes>
            <include>com.ravi.batch:*:EAR</include>
<include>com.ravi.presentation:*:EAR</include>
<include>com.ravi.properties:*:zip</include>
<include>com.ravi.dbscripts:*:zip</include>
        </includes>
        <!--<useProjectArtifact>true</useProjectArtifact>-->
        <outputDirectory>bin</outputDirectory>
<outputFileNameMapping>
                ${artifact.artifactId}.${artifact.extension}
         </outputFileNameMapping>
        <unpack>false</unpack>
    </dependencySet>  
</dependencySets>
</assembly>

No comments:

Post a Comment

 
Blogger Templates