MAVEN Project structure: aggregation

Source: Internet
Author: User

Project Aggregation [, Æɡr? ') ɡe??? N

Https://maven.apache.org/guides/introduction/introduction-to-the-pom.html

Https://maven.apache.org/guides/mini/guide-multiple-modules.html

Modular development (aggregation of all modules in one parent POM)

Use a parent pom to manage individual modules, control inter-module dependencies and build order

Start a simple demo to understand this structure

1. Create a parent pom (Maven Project)

<Projectxmlns= "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>Cn.zno</groupId>  <Artifactid>App-pom</Artifactid>  <version>1.0</version>  <Packaging>Pom</Packaging></Project>

2. Create a jar block (Maven module)

Right-click App-pom

New Maven Module

<Projectxmlns= "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>Cn.zno</groupId>    <Artifactid>App-pom</Artifactid>    <version>1.0</version>  </Parent>  <Artifactid>App-jar</Artifactid></Project>

3. Create a war module

<?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>Cn.zno</groupId>    <Artifactid>App-pom</Artifactid>    <version>1.0</version>  </Parent>  <Artifactid>App-war</Artifactid>  <Packaging>War</Packaging>  <name>App-war Maven Webapp</name>  <URL>http://maven.apache.org</URL>  <Dependencies>    <Dependency>      <groupId>Junit</groupId>      <Artifactid>Junit</Artifactid>      <version>3.8.1</version>      <Scope>Test</Scope>    </Dependency>  </Dependencies>  <Build>    <Finalname>App-war</Finalname>  </Build></Project>

Now the parent Pom is automatically modified to:

<Projectxmlns= "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>Cn.zno</groupId>  <Artifactid>App-pom</Artifactid>  <version>1.0</version>  <Packaging>Pom</Packaging>  <Modules>      <Module>App-jar</Module>      <Module>App-war</Module>  </Modules></Project>

Install App-pom now

Right-click App-pom, Run as, Maven install

[INFO] Scanning for projects ... [INFO]------------------------------------------------------------------------[INFO] Reactor Build order:[info] [                                                                         INFO] App-pom[info] app-jar[info] App-war Maven Webapp[info] [INFO]------------------------------------------------------------------------[INFO] Building App-pom 1.0[info ]------------------------------------------------------------------------[INFO] [INFO]---maven-install-plugin : 2.4:install (Default-install) @ app-pom---[INFO] installing F:\e\workspacetest\app-pom\pom.xml to C:\Users\wl\.m2\                                                                         Repository\cn\zno\app-pom\1.0\app-pom-1.0.pom[info] [INFO]------------------------------------------------------------------------[INFO] Building App-jar 1.0[info]-- ----------------------------------------------------------------------[INFO] [INFO]---maven-resources-plugin : 2.6:resources (default-resources) @ App-jar---[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform Depen dent! [INFO] Copying 0 Resource[info] [INFO]---maven-compiler-plugin:3.1:compile (default-compile) @ app-jar---[info] nothing to com Pile-all classes is up to Date[info] [INFO]---maven-resources-plugin:2.6:testresources (default-testresources) @ app- Jar---[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] Copying 0 Resource[info] [INFO]---maven-compiler-plugin:3.1:testcompile (default-testcompile) @ app-jar---[info] Nothing to Compile-all classes is up to Date[info] [INFO]---maven-surefire-plugin:2.12.4:test (default-test) @ app-ja R---[info] [INFO]---maven-jar-plugin:2.4:jar (default-jar) @ app-jar---[info] Building Jar:f:\e\workspacetest\app-po M\app-jar\target\app-jar-1.0.jar[info] [INFO]---maven-install-plugin:2.4:install (default-install) @ App-jar---[ INFO] Installing f:\e\workspacetest\app-pom\app-jar\target\app-jar-1.0.jar to C:\Users\wl\.m2\repository\cn\zno\app-jar\1.0\ App-jar-1.0.jar[info] Installing F:\e\workspacetest\app-pom\app-jar\pom.xml to C:\Users\wl\.m2\repository\cn\zno\ App-jar\1.0\app-jar-1.0.pom[info] [INFO]--------- ---------------------------------------------------------------[INFO] Building App-war Maven Webapp 1.0[info]------ ------------------------------------------------------------------[INFO] [INFO]---maven-resources-plugin:2.6:  Resources (default-resources) @ app-war---[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] Copying 0 Resource[info] [INFO]---maven-compiler-plugin:3.1:compile (default-compile) @ app-war---[info] No sources to Compile[info] [INFO]---maven-resources-plugin:2.6:testresources (default-testresources) @ app-war---[WARNING] Using Platform Encoding (Cp1252 Actually) to the copy filtered resources, i.e. build is platform dependent! [INFO] Skip non existing resourcedirectory f:\e\workspacetest\app-pom\app-war\src\test\resources[info] [INFO]--- Maven-compiler-plugin:3.1:testcompile (default-testcompile) @ app-war---[info] No sources to compile[info] [INFO]---MA Ven-surefire-plugin:2.12.4:test (default-test) @ app-war---[info] [INFO]---maven-war-plugin:2.2:war (default-war) @ App-war---[INFO] packaging Webapp[info] Assembling WebApp [App-war] in [F:\e\workspacetest\app-pom\app-war\target\ App-war][info] processing war Project[info] Copying webapp resources [F:\e\workspacetest\app-pom\app-war\src\main\ Webapp][info] WebApp assembled in [Msecs][info] Building War:f:\e\workspacetest\app-pom\app-war\target\app-war.war [INFO] Web-inf\web.xml already added, Skipping[info] [INFO]---maven-install-plugin:2.4:install (default-install) @ App-war-- -[info] Installing F:\e\workspacetest\app-pom\app-war\target\app-war.war to C:\Users\wl\.m2\repository\cn\Zno\app-war\1.0\app-war-1.0.war[info] Installing F:\e\workspacetest\app-pom\app-war\pom.xml to C:\Users\wl\.m2\ Repository\cn\zno\app-war\1.0\app-war-1.0.pom[info]----------------------------------------------------------- -------------[INFO] Reactor summary:[info] [info] app-pom ..... ..... ..... ....... .................. SUCCESS [0.674 s][info] app-jar ..... ..... ....... .................... SUCCESS [2.903 s][info] App-war Maven Webapp ......... .............. SUCCESS [0.759 s][info]------------------------------------------------------------------------[INFO] BUILD Success[info]------------------------------------------------------------------------[INFO] Total time:4.483 s[ INFO] finished at:2016-09-07t15:11:51+08:00[info] Final Memory:13m/111m[info]------------------------------------- -----------------------------------

Have done these things:

Install a pom file

Install a JAR file

Install a war file

Build Order Reference Official website:

The following relationships is honoured when sorting projects:

    • A project dependency on another module in the build
    • A plugin declaration where the plugin is another modules in the build
    • A plugin dependency on another module in the build
    • A build extension declaration on another module in the build
    • The order declared in the <modules> element (if no other rule applies)

Because App-war and App-jar have no dependencies, the build order is the last rule (Modules declaration order)

Why Modular Development
    • Division of labor Clear Code reuse
    • The SOA module facilitates distributed
    • Protect source Rights control
    • Local builds save time

1. The development process may encounter multiple items, inside the DAO, Servie, util reuse, form the code everywhere copy paste. Wait until you want to change the logic of the dumbfounded, because to change n place. Unnecessary increase in development costs and maintenance costs.

2. Soa that is considered after concurrent traffic increases is costly if the initial design does not have a service modularity.

3. Version control software svn, git, if the code is all in one place, although only a small task is assigned to a little bit of code, but all the code is to be downloaded.

4. Only modified a small function did not think of the need for the overall construction of a sudden, slowly slow.

MAVEN Project structure: aggregation

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.