Maven3 practical notes 07 inheritance

Source: Internet
Author: User

1. Inheritance
Previously, we learned about the aggregation mechanism of Maven, namely the pom of multiple modules. the xml file contains redundant and repeated content. To solve this problem, you can use the Maven Inheritance Mechanism. Just like Java inheritance, the parent class is like a template, if the subclass inherits from the parent class, some common methods and variables do not need to be repeated in the subclass. For details about how Java inherits from the memory, refer
Http://suhuanzheng7784877.iteye.com/blog/1000635
And the volume content in http://suhuanzheng7784877.iteye.com/blog/1000700. The Inheritance Mechanism of Maven is similar. After a parent-level Maven pom file defines related constants, dependencies, plug-ins, and other configurations, the actual project module can inherit the pom file of the Parent Project. Repeated items do not need to be displayed again. It is equivalent to the parent Maven project as a template, waiting for other sub-modules to inherit. However, the parent Maven project must be highly abstract and highly extract common parts (intersection ). I used the parent template pom made by the previous aggregation project module. In fact, many organizations also implemented this.
Java code
<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/maven-v4_0_0.xsd">
<ModelVersion> 4.0.0 </modelVersion>
<GroupId> com. liuyan. account </groupId>
<ArtifactId> MavenAccount-aggregator </artifactId>
<Version> 0.0.1-SNAPSHOT </version>
<Packaging> pom </packaging>

<Properties>
<Springversion> 2.5.6 </springversion>
<Junitversion> 2.5.6 </junitversion>
</Properties>

<Dependencies>
<Dependency>
<GroupId> org. springframework </groupId>
<ArtifactId> spring-core </artifactId>
<Version >$ {springversion} </version>
</Dependency>
<Dependency>
<GroupId> org. springframework </groupId>
<ArtifactId> spring-beans </artifactId>
<Version >$ {springversion} </version>
</Dependency>
<Dependency>
<GroupId> org. springframework </groupId>
<ArtifactId> spring-context </artifactId>
<Version >$ {springversion} </version>
</Dependency>
<Dependency>
<GroupId> org. springframework </groupId>
<ArtifactId> spring-context-support </artifactId>
<Version >$ {springversion} </version>
</Dependency>
<Dependency>
<GroupId> javax. mail </groupId>
<ArtifactId> mail </artifactId>
<Version> 1.4.1 </version>
</Dependency>
<Dependency>
<GroupId> junit </groupId>
<ArtifactId> junit </artifactId>
<Version> 4.7 </version>
<Scope> test </scope>
</Dependency>
<Dependency>
<GroupId> com. icegreen </groupId>
<ArtifactId> greenmail </artifactId>
<Version> 1.3.1b </version>
<Scope> test </scope>
</Dependency>
</Dependencies>

<Build>
<Resources>
<Resource>
<Directory> src/main/resource </directory>
</Resource>
</Resources>
<Plugins>
<Plugin>
<GroupId> org. apache. maven. plugins </groupId>
<ArtifactId> maven-source-plugin </artifactId>
<Version> 2.1.1 </version>
<Executions>
<Execution>
<Id> buildSource </id>
<Goals>
<Goal> jar-no-fork </goal>
& Nb

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.