I read this question on SO – How to add WAR inside EAR with Maven
In top voted answer by “joelittlejohn” –
“Now create a parent module (with pom) and add
the war module and the ear module to it. Make sure you set the parent
of the war and ear modules corrently. When you run mvn
package for this new parent, a war file will be built by the war
module and an ear file (containing the war) will be built by the ear
module.”
But why create a parent pom ? Why not just created a standard maven project with just a single pom. This single pom file contains the dependencies & modules, then generate the .ear file from this one pom file ?
Something like :
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<finalName>MyEarFile</finalName>
<version>5</version>
<generatedDescriptorLocation>${basedir}/src/main/application/META-INF</generatedDescriptorLocation>
<modules>
<webModule>
<groupId>com.your.group.id</groupId>
<artifactId>your-war-artifact</artifactId>
<uri>YouWarFile.war</uri>
<bundleFileName>YouWarFile.war</bundleFileName>
<contextRoot>/appname</contextRoot>
</webModule>
</modules>
</configuration>
<dependencies>
<dependency>
<groupId>com.your.group.id</groupId>
<artifactId>your-war-artifact</artifactId>
<version>your-war-version</version>
<type>war</type>
</dependency>
</dependencies>
</plugin>
It’s typical in maven to have a module for each war you want to build. And then the .ear file will contain multiple wars. So having a module each just provides a nice separation of duties. The parent pom just wraps it all together.