JavaGian , Free Online Tutorials, JavaGian provides tutorials and interview questions of all technology like java tutorial, android, java frameworks, javascript, ajax, core java, sql, python, php, c language etc. for beginners and professionals.
Learn how to create multi module maven project in eclipse IDE. In this maven tutorial, we will learn to create nested maven projects in eclipse.
1. Create multi module maven project
Let’s create a maven project having modules packaging ear, war and jar types. We are creating the structure of an enterprise application where 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 contain the service project which has common code to all war files and packaging type in JAR (Java ARchive).
Projects Relationship
1.1. Create parent project – packaging type ‘pom’
Create a new maven project in eclipse. Set it’s packaging type to ‘pom‘.
Create new maven projectFill maven group id and artifact idChange packaging jar to pom
1.2. Create maven module – packaging type ‘ear’
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.
Create new maven moduleAdd Module NameFill archetype details
1.3. Create maven modules – 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.
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 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.
Remove duplicate entries
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.