Introduction to Maven’s life cycle and common commands

Introduction and advantages of maven

Maven is a tool for project construction and management. It provides methods to help manage construction, documents, reports, dependencies, SCMs, publishing and distribution. It is convenient to compile code, manage dependencies, manage binary libraries, and so on. The advantage of Maven is that it can standardize, automate, efficiently and expand the project process. Using Maven itself and its plug-ins, it can also obtain code inspection reports, unit test coverage, continuous integration and so on

Maven advantages:

1. Automatic compilation and deployment of the project

2. Dependency management of project jar package

3. Plug in management of the project

Maven is based on the core concept of the construction life cycle. The creation and deployment of the whole project are carried out around the life cycle. A life cycle consists of several life cycle stages.

Maven has three built-in default lifecycles: default, clean and site

The default lifecycle handles your project deployment, the clean lifecycle handles project cleaning, and the site lifecycle handles the creation of site documents for your project.

Each of these build lifecycles consists of a different list of compilation phases, where the construction phase represents a phase defined in the lifecycle.

For example, the lifecycle of default includes the following phases (for a complete list of lifecycle phases, see lifecycle reference):

Validate - verify that the project is correct. For all necessary information, please visit compile - compile the source code of the project test - Test and compile the source code using the appropriate unit test framework. These tests should not require the code to be packaged or deployed package - to compile the code and package it in its distribution format, such as a jar. Verify - check the running integration test results to ensure that the quality standards are met. Install - install the package locally into the local repository and use it as a dependency of other projects. Deploy - complete the build environment, copy the final package to the remote warehouse and share it with other developers and projects

During the default life cycle, Maven will first verify the project, then try to compile the source code, run the binaries (such as jars) encapsulated for the test, run the integration test for the software package, verify the integration test, install the verification package to the local warehouse, and finally deploy the installed software package to the remote repository.

Common Maven command lines:

MVN clean delete any generated output (such as class files or jar files) MVN test run unit tests for the project MVN install copy project components to your local repository MVN deploy copy project components to a remote repository MVN site create project documents (such as reports or JavaDocs).

mvn compile

compile

mvn validate

PS: let's take a look at the commands commonly used by Maven in eclipse

Right click a maven project shortcut and click Run as to find several Maven commands:

  Maven Build:

This command is used to compile the Maven project. After executing the command, the corresponding class file will be generated in the classes in the target folder.

  Maven Clean:

Delete the target folder, that is, delete the generated package package, class and other files.

  Maven Test:

First, compile automatically and run all test cases.

  Maven install:

Publish and generate the corresponding package package (in the form of war and jar).

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>