Creation of multi-module inheritance and aggregation for MAVEN engineering under Eclipse

Source: Internet
Author: User

Multi-module inheritance and aggregation is essential when using MAVEN to manage projects, and this article briefly explains the creation of multi-module projects under the Eclipse IDE.


1.Maven Multi-Module aggregation


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/57/85/wKioL1Sc1AujsKKSAAChHDN3Azg136.jpg "title=" Aggretion_module.png "alt=" Wkiol1sc1aujskksaachhdn3azg136.jpg "/>

A MAVEN project creates multiple modules and then organizes the modules that are actually applied to them with a dedicated management module.


2.Maven Multi-Module inheritance

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/57/87/wKiom1Sc1EzQiS_gAADewbZUzho728.jpg "title=" Extends_module.png "alt=" Wkiom1sc1ezqis_gaadewbzuzho728.jpg "/>

The submodule receives the Pom.xml configuration information in the parent module by inheriting the parent module.


3.Maven Multi-Module inheritance + aggregation


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/57/85/wKioL1Sc1YLiIccuAAD7NveN3s8560.jpg "title=" Aggretion_extends_module.png "alt=" Wkiol1sc1yliiccuaad7nven3s8560.jpg "/>

is to combine 1 and 2, you can use the parent module as an aggregation module and a parent module so that the parent module can aggregate (organize) its submodules, and the submodule can inherit the parent module.


4. The relationship between aggregation and inheritance

difference :

    • For an aggregation module, it knows which modules are aggregated, but the aggregation modules are independent of each other.

    • For the parent pom of an inheritance relationship, it does not know which submodules inherit it, but those submodules must know their parent pom.

Common denominator:

    • The packaging of the parent pom in the aggregation pom and the inheritance relationship are all pom.

    • The parent module in the aggregation module and the inheritance relationship has no actual content except the POM.

5. Use Eclipse to build a project that integrates aggregation and inheritance


5.1 Create a MAVEN project, which acts as an aggregation module

<groupid>secondriver</groupid><artifactid>code-parent</artifactid><version>0.0.1 -snapshot</version><packaging>pom</packaging><name>code-parent</name><url> Http://maven.apache.org</url>

5.2 Create the Javase maven module (Code-utils, pictured in Code-utilss) and select the Code-parent project above as the parent project.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/57/88/wKiom1Sc4v6RIrDwAAD-lGR9cPQ334.jpg "title=" Eclipse-ui.png "alt=" Wkiom1sc4v6rirdwaad-lgr9cpq334.jpg "/>

5.3 Ibid., create javaweb maven module (code-web), and select the above Code-parent project as the character project.

5.4 The directory structure in eclipse

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/57/88/wKiom1Sc48bBvuO5AAF7TMkWmSI279.jpg "title=" Maven-parent-utils-web.png "alt=" Wkiom1sc48bbvuo5aaf7tmkwmsi279.jpg "/>


On the way there are three projects, accurate said Code-parent is Maven project, Code-utils,code-web is the Code-parent project under the two modules; code-parent it was aggregated, code-utils, Code-web inherited the Code-parent.

Directory structure of the local file system:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/57/86/wKioL1Sc5pmBkeeaAACB9VYDC3E069.jpg "style=" float: none; "title=" Sys-modules.png "alt=" wkiol1sc5pmbkeeaaacb9vydc3e069.jpg "/>650" this.width=650; "src=" http:// S3.51cto.com/wyfs02/m01/57/88/wkiom1sc5evdzcxeaab-ykngihg717.jpg "title=" Parent.png "alt=" Wkiom1sc5evdzcxeaab-ykngihg717.jpg "/>

The Pom file under Code-parent inherits the Pom.xml for the Pom.xml under the parent pom.xml,code-utils and Code-web.


5.5 Code-parent's Pom.xml

<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>secondriver</groupId> <artifactId>code-parent</artifactId><version>0.0.1-SNAPSHOT</version><packaging> pom</packaging><name>code-parent</name><url>http://maven.apache.org</url>< modules><module>code-utils</module><module>code-web</module></modules>< properties><project.build.sourceencoding>utf-8</project.build.sourceencoding>< project.reporting.outputencoding>utf-8</project.reporting.outputencoding><junit.version>4.10 </junit.version></properties><description> This is the parent module, which is integrated with the Submodule, which inherits the module. The main role is the unified management of public configuration </description><dependencies><dependency> <groupid>junit</groupid><artifactid>junit</artifactid><version>${junit.version} </version><scope>test</scope></dependency></dependencies>< Dependencymanagement><dependencies></dependencies></dependencymanagement></project>


The value of packaging in the configuration is pom, which means that code-parent is an aggregation module or a parent module, where it belongs to both. The modules is configured with two modules, namely Code-utils and Code-web.


The pom.xml of 5.6code-utils and Code-web

    • Code-parent/code-utils/pom.xml

<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>secondriver</groupid>< artifactid>code-parent</artifactid><version>0.0.1-snapshot</version></parent>< Artifactid>code-utils</artifactid><name>code-utils</name></project>

The default packaging value in the configuration is jar.


    • Code-parent/code-web/pom.xml

<?xml version= "1.0"? ><projectxsi:schemalocation= "http://maven.apache.org/POM/4.0.0/http Maven.apache.org/xsd/maven-4.0.0.xsd "xmlns=" http://maven.apache.org/POM/4.0.0 "xmlns:xsi=" http://www.w3.org/ 2001/xmlschema-instance "><modelVersion>4.0.0</modelVersion><parent><groupId> secondriver</groupid><artifactid>code-parent</artifactid><version>0.0.1-snapshot</ Version></parent><artifactid>code-web</artifactid><packaging>war</packaging> <name>code-web Maven webapp</name><url>http://maven.apache.org</url><build>< Finalname>code-web</finalname></build></project>


The MAVEN project to create a multi-module through eclipse is complete. As for how Pom.xml is configured, it is another matter, for more information on MAVEN's pom.xml configuration see: Http://maven.apache.org/pom.html#Resources


This article is from the "Red Horse Red" blog, please be sure to keep this source http://aiilive.blog.51cto.com/1925756/1596192

Creation of multi-module inheritance and aggregation for MAVEN engineering under Eclipse

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.