MAVEN builds multi-module projects

Source: Internet
Author: User

First. introduction of multi-module project

All real projects managed with Mavan should be sub-modules, each of which corresponds to a pom.xml, and their inheritance and aggregation are interrelated. After partitioning the module, importing Eclipse into N projects, which can bring complexity and inconvenience to development, why use it. The reasons are as follows: 

1, easy to reuse, such as app-util these modules can evolve into a basic public class for all projects to use, which is one of the most important purposes of modularity. 

2, because you divided the module, each module configuration in their own pom.xml, no longer to a complex pom to find their own configuration. 

3, if you just work on the app-util, you do not need to build the entire project, as long as the App-util directory run MVN command, this can save time, especially when the project is huge, build more time-consuming time. 

4, some modules, such as app-util by all people rely on, but you do not want to change for everyone, you can completely take app-util out to another project, only provide the jar package, no modification permissions.

Second. structure of multi-module projects

A simple MAVEN module structure is this:  ----app-parent               |--pom.xml (POM)              |              |--App-util               |        |--pom.xml (JAR)              |              |--App-dao               |        |--pom.xml (JAR)              |              |--App-core               |        |--pom.xml (jar)              |              |--App-web                        |--pom.xml (War)  

In the simple diagram above, there is a parent project (app-parent) that aggregates many sub-items (app-util, App-dao, App-core, App-web). Each project, whether parent or child, contains a pom.xml file. Also note that the parentheses indicate the package type for each item. The parent project is a Pom and can only be a pom. A child project has a jar, or war. Specific considerations are based on what it contains. 

Third. steps to create a multi-module project on Eclipse

Let's take a look at the steps to create a multi-module project in Eclipse: 

1. First create a parent project New->project->maven->maven project, click Next, Select Maven-archetype-site-simple, as follows


Then click Next, enter values in GroupID and Artifactid, General GroupID refers to the project organization, for example, Qihoo company, is Com.qihoo, Artifactid is the unique identifier of the project, the actual corresponding project name, Here our project name is called App.


Select Done, and a project is generated in eclipse.


 2, then create a subproject to delete the src file in the Project app, the main function of the parent project is to manage the other sub-projects, which are not written by themselves, so it is possible to keep only one pom.xml. Select the Project app, right click, select New->project->maven->maven module, fill in module name (such as App-util, App-core, App-dao, App-web) Click Next, select Maven-archetype-site-quickstart (use when building app-util, App-core, App-dao) or Maven-archetype-webapp ( When building the App-web layer), then select Done.




The effect after creation


3. Finally set the dependency relationship here App-web relies on App-core, app-util,app-core dependent app-util, App-dao, note: Dependency has transitivity, dependency in Pom.xml Setup method is as follows:


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.