Wednesday, 1 February 2017

Adding multiple modules in one project : eclipse


A project can consist multiple modules, where a module is a project with some dependency on each other.


Create a Parent project:  ( which behaves like parent to further maven modules)

File – New – Other – Maven Project
Check “Create a simple Project (Skip archetype selection)
Next
Group id : com.parent
Artifact id : parent
Packaging : POM ß
Finish

This is how pom.xml looks like

<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.parent</groupId>
  <artifactId>parent</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>
</project>

Create a child / maven module:

File – New – Other – Maven Module
Check “Create a simple Project (Skip archetype selection)
Module Name: Child
Parent Project: Parent
Finish

This is how pom.xml looks like
<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>
  <parent>
    <groupId>com.parent</groupId>
    <artifactId>parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <artifactId>child</artifactId>
</project>

Observations:

In child pom.xml:  observe that parent tag, which talks about who is my parent

Note: any dependencies declared in parent pom.xml are available to child pom.xml by default.

Testing:

GO to parent pom.xml file folder and say > mvn clean
Now two projects will be created.





No comments:

Post a Comment