In this guide, we learn how to create Maven Multi-Module using Command Line with very easy steps. A multi-module project is defined by a parent POM referencing one or more sub-modules. In this example, we will create a blogger web application with different modules. Let's create a blogger as parent project and it's 3 sub-modules are blogger-core, blogger-common, blogger-web.
Real-world examples of maven multi-module projects are:
Below are the steps to create parent and sub-modules projects.
To create the Parent project:
mvn archetype:generate -DgroupId=com.companyname.blogger -DartifactId=blogger Note that whole command should be a single line. After build success, we will see below output in the command line console.
Open pom.xml of above-created parent-project and change the packaging to pom.
The complete pom.xml
If you don't change this pom.xml then you will get below build fail error:
Change directory via below command
Let's create sub-modules in blogger parent project.
Create blogger-core module.
Create blogger-common module
Create blogger-web module and it is web application packaged with war file. The archetype for maven web application is
Now if you open the blogger parent project pom.xml, you will find all three modules being added in there.
Also, in each sub-module’s pom.xml, a parent section being added.
blogger-core module is package with jar
blogger-common module is a package with a jar.
blogger-web module is already packaging with war.
Let's updated pom.xml files for all the parent and sub-modules.
blogger parent project pom.xml:
blogger-core sub-module pom.xml:
blogger-common sub-module pom.xml:
blogger-web sub-module pom.xml:
To test all the multi-module project setup is correct then run below maven common on blogger parent project:
That's it. Now can import this project into Eclipse IDE. In Eclipse , File -> Import -> Maven -> Existing Maven projects
In this guide, we have learned how to create maven Multi-Module using Command Line by taking the bloggerproject as an example.
The source code of this multi-module project is available on GitHub.
Read my favorite Maven Developers Guide.