Beginner Maven

In software development, in addition to the analysis of requirements, software design, and code writing, there are also some piecemeal work, such as: project cleaning, compiling, publishing, and project dependency management. Although these daily actions do not create actual code, they will affect our work efficiency. I believe that friends who have managed dependencies and code bases should be familiar with the impact of these trivial daily activities on development, and Maven is used to simplify these affairs. Tool of. I have come into contact with Maven at work before, here is a brief description of my understanding of this tool.

Maven is a project under Apache and is a project management tool. Its functions are mainly divided into two parts:

  • Dependency management, which can easily manage various components that the project depends on;
  • Project build. Compile, test, package, publish, etc. of the project.

Dependency management
Maven uses pom.xml to describe the project, and manages it abstractly; and puts the specific dependent components under the local warehouse for the project to use in the construction process.

The pom.xml file is a logical description of the entire project; all descriptions about the project are under the <project> element; the description of the project itself is three-dimensionally represented by <groupId>, <artficatId>, and <version> Sure. Often, the information is different for different projects. The dependencies of the project are managed by each <dependency> tag under <dependencies>. Combined with comments, you can clearly describe a project's dependent components and avoid confusion.

Repositories are the actual support for project dependencies. Maven has a central repository that stores most of the mainstream components for developers to download, and the identification of these components starts with the previous pom.xml. Simply put, as long as the pom.xml file is written, the project can be built relatively easily when the network is smooth. Of course, the central warehouse may also be insufficient. For example, a large number of accesses cause its speed to drop, or some components are not in the central warehouse. These problems can be solved by building a private server through Nexus. Maven downloads dependency packages from the central repository or private servers (collectively referred to as remote repositories) to the local repository according to the guidelines of pom.xml, and then manages them in a unified manner to prevent various dependency packages from being scattered around.

When Maven creates a project, you can choose the Archtype (skeleton) to create it. Different archtypes carry different components by default, corresponding to different projects.

In simple cases, after editing the pom.xml, we can create the project and manage its dependencies clearly; the

project builds
Maven does it through life cycles. Maven has three life cycles: clean, default, site, corresponding to cleaning, core (there are many things here, including inspection, testing, Dabao, submitted to the local warehouse, temporarily called "core"), deployment. These three life cycles are independent of each other.

There are goals inside the Maven lifecycle. For example, there are three goals inside clean: pre-clean, clean, and post-clean. When executing, if I execute clean, pre-clean will also be executed, and when post is executed, both pre-clean and clean will be executed. The other two life cycles are also composed of multiple targets, and the order of execution is also the same, which will not be described here. Please refer to: Maven Life Cycle Details .

For each goal, their behavior is not fixed, but determined by the Maven plugin. We can also write Maven plug-ins for projects by ourselves. These can also be configured in pom.xml.

Under the correct setting, Maven can help us to clean up, compile, test, package and other functions of the project at one time, which liberates developers to a certain extent.

This article is my own understanding after reading Mr. Xu Xiaobin's "Maven Combat", which can only be approximated. The link above also points to Mr. Xu's blog.

I'm still looking for a job tomorrow, so hurry up

and see how to use bbcode to typeset what I've written after writing the interview questions;


2016-02-23

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326683790&siteId=291194637