0

How to create multi-module application in Maven using Eclipse

Background

Maven allows you to break down your application into multiple modules. The presentation, service, and integration layers will each be in separate module. This article demonstrates how to create just that.

Software Environment

  • Windows 7 Professional SP1
  • Java 1.7 (1.7.0_67 – Windows x86)
  • Eclipse Luna

First, create the parent project

The parent project is of pom type. As you can see later, there are three types (package types) in Maven – jar, war, and pom.

1. Go to New -> Others… and choose Maven Project under Maven

maven-parent-pom

Then, click Next.

2. Create a simple project

maven-parent-pom2

3. Configure the project

maven-parent-pom3

Click Finish and the parent project will be created.

4.  The parent project

maven-parent-pom4

Second, create the service module

Here, you create a Maven module. First, you created a Maven Project. Now, you are creating a Maven Module.

1. Go to New -> Others… and choose Maven Module under Maven

maven-module1-1

2. Create a simple project

maven-module1-2

Please note that although it say “Create a simple project (skip archetype select)” , we are still creating a Maven Module. You may need to browse and select an available parent project. On the screenshot above, Parent Project is set to multimoduleapp.

Tick the checkbox and hit the Finish button.

3. Configure the module

maven-module1-3

Hit Finish to complete the process.

4. The module

There you go! We have successfully created a multimodule (somewhat) project. You may create another module, e.g., multimoduleapp-integration, using the same steps for Maven Modules.

maven-module1-4

Third, create the presentation layer

The presentation layer is just another Maven Module with a slight difference. Instead of ticking the “Create a simple project (skip archetype select)” option, simply hit Next.

maven-module2-1

Then, choose an archetype. Select maven-archetype-webapp. With this, Maven will generate a web (war) module.

maven-module2-2

Simply click Next to proceed.

maven-module2-3

Simply click Finish to complete the process.

maven-module2-4

Karl San Gabriel

Karl San Gabriel

Java and Enterprise Technologies Expert