Maven - Build a Multiple Module Project with Maven - maven tutorial
Introduction
- This document is based on:
- Eclipse 4.6 (NEON)
- You are viewing the advanced Maven. If you are a beginner Maven. You should look at the documentation for beginners Maven (Maven Hello world) at:
maven tutorial tags : apache maven , maven repository , maven central
Model example
- This is the model example in this document.
learn maven tutorial - maven multiple project - maven example
- The objective of the guidelines is:
- How a module using other module in Maven
- Packing multiple Module using Maven (output: jar, war).
- MathWebApp: is a WebApp project
- MathLibrary: is a library Project, contains utility classes used by MathWebApp.
- MavenParent: will pack two projects above, it is a parent module. MavenParent will:
- Packing MathLibary to a jar file
- Packing MathWebApp to a file war.
Create project MathLibrary
learn maven tutorial - maven multiple project select a wizard - maven example
- This is a simple Project, so we don't need to select a Maven archetype.
- Select:
- Create a simple project (skip archetype selection)
learn maven tutorial - maven example maven multiple project new -
- Group Id: org.o7planning
- Artifact Id: MathLibrary
- Packaging: jar
- Skip parent module information.
learn maven tutorial - maven multiple configure project - maven example
- Project is created.
learn maven tutorial - maven multiple project project explorer - maven example
- Create class MathUtils:
MathUtils.java code
Create project MathWebApp
learn maven tutorial -maven multiple select projectname location - maven example
learn maven tutorial - maven multiple select new project - maven example
- Select maven-archetype-webapp archetype. Eclipse will create a Project Maven that has the structure of a web application.
learn maven tutorial -maven multiple project select archetype - maven example
- Group Id: org.o7planning
- Artifact Id: MathWebApp
- Version: 0.0.2-SNAPSHOT
- Package: org.o7planning.mathwebapp
learn maven tutorial -maven specify archytype parameter- maven example
- Here is a screenshot MathWebApp project has been created. You may see an error message somewhere on the Project, do not worry about it, cause you have not declared Servlet library.
learn maven tutorial - maven multiple project source - maven example
- Eclipse create this project structure may be wrong. You need to check out.
learn maven tutorial - maven multiple project create eclipse - maven example
- Open file pom.xml
learn maven tutorial - maven multple project mathwebapp - maven example
Add code
learn maven tutorial - maven multiple pom xml - maven example
- Now error has no longer exist:
learn maven tutorial - maven project explorer - maven example
Continue configure Maven, MathWebApp use MathLibrary:
maven tutorial tags : apache maven , maven repository , maven central
MathWebApp/pom.xml
- Edit file index.jsp using MathUtils, class in project MathLibrary.
index.jsp
Create project MavenParent
- Create a Common Java Project.
- File/New/Other..
learn maven tutorial -maven java project - maven example
learn maven tutorial - maven multiple javaparent- maven example
learn maven tutorial - maven multiple project java settings - maven example
maven configure project
- Group Id: org.o7planning
- Artifact Id: MavenParent
- Version: 1.0.0-SNAPSHOT
- Packaging: pom
learn maven tutorial - maven snapsot project- maven example
learn maven tutorial - maven multiple package explorer - maven example
Configure Maven the relationship between the Projects
- This image describes briefly the Maven relational configuration among Projects.
learn maven tutorial - maven parent class - maven example
- Open file pom.xml of 2 project MathLibrary & MathWebApp and add:
Open pom.xml of MavenParent add:
maven tutorial tags : apache maven , maven repository , maven central
MathLibrary/pom.xml
MathWebApp/pom.xml
MavenParent/pom.xml
Install projects
- Right-click project MavenParent select:
- Run As/Maven install.
learn maven tutorial - maven installation - maven example
Result:
learn maven tutorial - maven multiple project result - maven example
learn maven tutorial - maven package explorer - maven example