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