Learn how to create a multi-module maven project in eclipse IDE. In this maven tutorial, we will learn to create nested maven projects in Eclipse.
1. Multi-module Project Structure
Let’s create a maven project having modules packaging ear, war and jar types. We are creating the structure of an enterprise application where the application will be deployed to applications servers (e.g. Weblogic, WebSphere) as an EAR (Enterprise Application aRchive) file.
This EAR will contain one (or many) WAR (Web Application Resource) files and each war will include the service project which has common code to all war files.

1.1. Create Parent Project with Packaging type ‘pom’
Create a new maven project in eclipse. Set it’s packaging type to ‘pom‘.



1.2. Create Child Project with EAR Packaging
Create a new maven module in the parent project. Change its packaging type to 'ear'
. This module can have maven ear plugin which will ultimately build the ear file to be deployed on servers.



1.3. Create Projects with Packaging type ‘war’ and ‘jar’
Similar to ear module, create two more modules for war file and service jar file. Change their packaging respectively and add maven plugins.
1.4. Final Result
Now observe the final project structure in eclipse and verify the pom.xml files for all projects.
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.howtodoinjava.app</groupId>
<artifactId>HelloWorldApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>HelloWorldApp</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<modules>
<module>web</module>
<module>service</module>
<module>ear</module>
</modules>
</project>
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.howtodoinjava.app</groupId>
<artifactId>HelloWorldApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>ear</artifactId>
<name>ear</name>
<packaging>ear</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.howtodoinjava.app</groupId>
<artifactId>web</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<modules>
<webModule>
<groupId>com.howtodoinjava.app</groupId>
<artifactId>web</artifactId>
<uri>web-0.0.1-SNAPSHOT.war</uri>
<!-- Set custom context root -->
<contextRoot>/application</contextRoot>
</webModule>
</modules>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.howtodoinjava.app</groupId>
<artifactId>HelloWorldApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>ear</artifactId>
<name>ear</name>
<packaging>ear</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.howtodoinjava.app</groupId>
<artifactId>web</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<modules>
<webModule>
<groupId>com.howtodoinjava.app</groupId>
<artifactId>web</artifactId>
<uri>web-0.0.1-SNAPSHOT.war</uri>
<!-- Set custom context root -->
<contextRoot>/application</contextRoot>
</webModule>
</modules>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.howtodoinjava.app</groupId>
<artifactId>HelloWorldApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.howtodoinjava.app</groupId>
<artifactId>service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>service</name>
<url>http://maven.apache.org</url>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
To build the projects, run $mvn clean install
command from the console.
E:\devsetup\workspacetemp\HelloWorldApp>mvn clean install
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] HelloWorldApp [pom]
[INFO] service [jar]
[INFO] web [war]
[INFO] ear [ear]
[INFO]
...
...
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ service ---
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar: E:\devsetup\workspacetemp\HelloWorldApp\service\target\service-0.0.1-SNAPSHOT.jar
[INFO]
...
...
[INFO] Packaging webapp
[INFO] Assembling webapp [web] in [E:\devsetup\workspacetemp\HelloWorldApp\web\target\web-0.0.1-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [E:\devsetup\workspacetemp\HelloWorldApp\web\src\main\webapp]
[INFO] Webapp assembled in [47 msecs]
[INFO] Building war: E:\devsetup\workspacetemp\HelloWorldApp\web\target\web-0.0.1-SNAPSHOT.war
[INFO] WEB-INF\web.xml already added, skipping
[INFO]
...
...
[INFO]
[INFO] --- maven-ear-plugin:3.0.1:ear (default-ear) @ ear ---
[INFO] Copying artifact [war:com.howtodoinjava.app:web:0.0.1-SNAPSHOT] to [web-0.0.1-SNAPSHOT.war]
[INFO] Copy ear sources to E:\devsetup\workspacetemp\HelloWorldApp\ear\target\ear-0.0.1-SNAPSHOT
[INFO] Building jar: E:\devsetup\workspacetemp\HelloWorldApp\ear\target\ear-0.0.1-SNAPSHOT.ear
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] HelloWorldApp 0.0.1-SNAPSHOT ....................... SUCCESS [ 0.328 s]
[INFO] service ............................................ SUCCESS [ 0.839 s]
[INFO] web ................................................ SUCCESS [ 0.838 s]
[INFO] ear 0.0.1-SNAPSHOT ................................. SUCCESS [ 0.588 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.749 s
[INFO] Finished at: 2018-11-18T15:04:52+05:30
[INFO] ------------------------------------------------------------------------
The build generates an ear file with name ear-0.0.1-SNAPSHOT.ear
.
Feel free to change the name of projects and generated packages as per your need.
2. FAQs
2.1. GroupId is duplicate of parent groupId
Maven child projects inherit properties from the parent project. If either group id or version id is same as parent project for any maven module/project, then we can simply remove this entry.

2.2. Artifact is not a dependency of the project
We may face this error when have added the module dependency (war) without specifying the type attribute.

Drop me your question related to creating a multi-module maven project in eclipse IDE.
Happy Learning !!
Hi,
I am creating an application using maven multi modules for the backend and Angular for the frontend.
Now I want to deploy both frontend and backend separately. Could you tell me how to do. because I do not have any web module in my backend application.
Thanks.
You need to create two applications. One maven application for backend code. Another UI application of Angular code. Both should be built and deployed separately.
It’s exactly what I did.
Now I can deploy Angular web app. But don’t know how to do with the backend as I can’t package it in war.
If you are using Spring boot then you can use https://start.spring.io/ and select packaging as war while generating the starter project.
If its not what you are looking, then please explain your issue.
Finally I did it.
I was just packaging the wrong module in war. That’s why it didn’t walk.
It’s ok now. Thanks for your help.
I’m case of moving this to GitHub repository do I have to move all three projects to GitHub repo.
Yes
How to run the builded applications beacause i cannot run with java jar beacause it is giving no manifest attribute?
Hi,
Can you think of any reason why the deployment assembly on an EAR project (in project properties) would be empty? I think that is causing the EAR to not contain any of the modules underneath, so that when I deploy it to the local JBoss server, it is not a valid EAR. Looking for any suggesting why that deployment assembly would be empty.
Thanks,
Steve