About POM (Project Object Model)

Source: Internet
Author: User

1 Concept Introduction

All configurations for a project are placed in the POM file: Define the type of project, name, manage dependencies, customize plugin behavior, and so on. For example, you can configure the compiler plugin to use java1.5 to compile.

[HTML]View PlainCopyPrint?
  1. < Project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/ Xmlschema-instance "
  2. xsi:schemalocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
  3. < modelversion >4.0.0</modelversion>
  4. < groupId >com.mycompany.helloworld</groupId>
  5. < Artifactid >helloworld</artifactid>
  6. < version >1.0-snapshot</version>
  7. < Packaging >jar</packaging>
  8. < name >helloworld</name>
  9. < URL >http://maven.apache.org</url>
  10. < Properties >
  11. < project.build.sourceEncoding > UTF-8</project.build.sourceEncoding>
  12. </ Properties >
  13. < Dependencies >
  14. < Dependency >
  15. < groupId >junit</groupId>
  16. < Artifactid >junit</artifactid>
  17. < version >3.8.1</version>
  18. < Scope >Test</scope>
  19. </ Dependency >
  20. </ Dependencies >
  21.   </ project >       
  <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.mycompany.helloworld</groupId> <artifacti D>helloworld</artifactid> <version>1.0-SNAPSHOT</version> <packaging>jar</packagin         g> <name>helloworld</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <d ependencies> <dependency> <groupId>junit</groupId> <artifactid>junit&lt ;/artifactid> <version>3.8.1</version> <scope>test</scope> </depend Ency> </dependencies> </project>     

In POM, Groupid,artifactid, packaging, and version are called Maven coordinates, which uniquely determine a component. With maven coordinates, we can use it to specify other projects, plugins, or parent projects on which our project depends.


    


Typically, large projects are generally divided into sub-projects. In this case, each subproject will have its own POM file, and then they will have a common parent project. This makes it possible to build all of the child projects as long as the parent project is built. The Pom of the subproject inherits the parent project's POM. In addition, all POM has inherited a super-pom. Super-pom sets some default values, such as the default directory structure mentioned earlier, the default plug-in, and so on, which follows the principle that the Convention is better than the configuration. Such as:


    


2 inheritance and aggregation of pom files

Inherited

Common configuration-dependencies (including public class libraries, plug-ins, information configurations) are typically put into a pom file for a parent project, and then the Pom file for other projects is inherited by the development. The inherited code is as follows:


    


It is important to note that the child pom file does not inherit all of its dependencies unconditionally, such as plugins, class libraries, and so on, once it inherits the parent Pom. If the child Pom wants to inherit a plugin from the parent pom, it is only necessary to introduce the GroupID and artifactid information of the plug-in in the parent pom (without having to write other configuration information for the plugin). In this way, a child pom can selectively inherit what it needs.


    


Polymerization

That is, a large project typically has an empty MAVEN project (only the Pom file, no Java code) as the parent project, and the project's Pom file (in the modules tag) aggregates the pom files for the other subproject, and then builds all the sub-projects as long as the parent project is built.


    



From for notes (Wiz)

About POM (Project Object Model)

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.