Ant is a software build tool, and Maven is positioned as a software project management and understanding tool. In addition to ant functions, Maven also adds the following main functions:
1) use the project object model to manage software projects;
2) More built-in implicit rules make building files easier;
3) built-in dependency management and repository for dependency management and Unified Storage;
4) built-in software build lifecycle;
One POM (Project object model) and Project Management
Each Maven project contains a pom. xml file, and other project-related information is stored to achieve certain project management functions. For example, the project configuration, defect tracking system information, project organization, license agreement, project path, dependencies, and other information are included.
The typical Pom. XML is as follows:
<Project... >
<Modelversion> 4.0.0 </modelversion>
<! -- The basics -->
<Groupid>... </groupid>
<Artifactid>... </artifactid>
<Version>... </version>
<Packaging>... </packaging>
<Dependencies>... </dependencies>
<Parent>... </parent>
<Dependencymanagement>... </dependencymanagement>
<Modules>... </modules>
<Properties>... </Properties>
<! -- Build settings -->
<Build>... </build>
<Reporting>... </reporting>
<! -- Project meta data -->
<Name>... </Name>
<Description>... </description>
<URL>... </URL>
<Inceptionyear>... </inceptionyear>
<Licenses>... </licenses>
<Organization>... </organization>
<Developers>... </developers>
<Contributors>... </contributors>
<! -- Environment -->
<Issuemanagement>... </issuemanagement>
<Cimanagement>... </cimanagement>
<MailingLists>... </MailingLists>
<SCM>... </SCM>
<Prerequisites>... </prerequisites>
<Repositories>... </repositories>
<Pluginrepositories>... </pluginrepositories>
<Distributionmanagement>... </distributionmanagement>
<Profiles>... </profiles>
</Project>
2. Invisible rules and simple build files
The directory structure of the maven project must be as follows:
Maven also has a built-in build lifecycle, which defines tasks such as build, test, package, and deploy.
The Maven project directory rules and built-in build lifecycle make the Build File simple. For example, the following build file does not even contain the definition of build, package, and other tasks, however, we can call wvm package and other built-in tasks:
<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. APP </groupid> <artifactid> my-app </artifactid> <packaging> jar </packaging> <version> 1.0-Snapshot </version> <Name> Maven Quick Start Archetype </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> </Project>
3. Dependency management and repository
Maven dependence management is used to manage all dependences of this project, and dependence is automatically searched and downloaded in dependence repository.
1) dependency management
For example, since the project, MySQL is as follows:
<Dependencymanagement>
<Dependencies>
<Dependency>
<Groupid> mysql </groupid>
<Artifactid> mysql-connector-Java </artifactid>
<Version> 5.1.2 </version>
</Dependency>
<Dependencies>
</Dependencymanagement>
<Dependency>
<Groupid> mysql </groupid>
<Artifactid> mysql-connector-Java </artifactid>
</Dependency>
2) dependence Repository
A better solution is that the company or each team has its own repository, for example:
4. Definition of building lifecycle
The build lifecycle explicitly defines the build, test, and release processes, which are the core of each Maven project. Maven contains three built-in lifecycles: Default, clean, and site.
1) The default lifecycle processes compilation, testing, and deployment of the project. It consists of more than 20 stages. The main stages are as follows:
Validate: Verify that all project information is available and correct
Compile: CompileSource code
Test: run the test in a set of frameworks.
Package: packaged and compiled in the published formatCode
Integration-test: Process (deploy) release packages in the integrated test environment
Verify: checks whether the release package is correctly available
Install: Install the release package on the local repository
Deploy: Install the release package on remote Repository
The preceding stages are sequentially executed. When a stage is executed, all stages before the stage are automatically executed.
2) The clean lifecycle process involves three phases: Pre-clean, clean, and post-clean.
3) The site life cycle processes the generation and deployment of project site documents, including the following stages:
Pre-site, site, post-site, and site-Deploy. Site-deploy is used to deploy the site document to the specified web server.
Complete!