Introduction to the basic concepts of maven
Purpose of this article
Continuing from the previous article on what it looked like before maven appeared , and continue to introduce the basic situation, I plan to write maven
this article only , and I will talk about it separately in the next article .maven
仓库
坐标
版本
text
1. The emergence of maven
The previous article wrote about various problems before the emergence of maven and the growing demand. In the end, some masters have already scratched their heads and couldn't help but make big moves, creating various project management tools to benefit us.
The emergence of project management tools is also based on the actual needs of these large number of projects, and the masters have abstracted a complete management model to restrict everyone. As long as you follow the constraints in the world, you can directly use a large number of mature maven plug-ins to complete tasks and realize projects. automatic dependency.
1.1 maven definition
maven
Translated as "expert, expert", it can also be translated as "accumulation of knowledge". As an open source project in the Apache organization, maven is a cross-platform project management tool (windows/mac/linux are all the same commands). The main function is based on the java platform 项目构建
, 依赖管理
and 项目信息管理
. Regardless of small open source library projects, enterprise-level applications, traditional development, or agile models, it can show its talents very well. (From "Maven Actual Combat")
maven
Through the passage 约定
, major companies will jar
prepare their own projects in a public warehouse (central warehouse) in advance, and provide the download address to the outside world. As long as the development project is configured according to the structure of the maven project, it can be downloaded anytime and anywhere. The project needs to depend on jar
the package, and it is guaranteed 源码与依赖分离
, 多个项目共用依赖
saving a lot of time wasted in building, and at the same time, it can have maven
some help from rich plug-ins.
2. maven coordinates
maven
There is a concept of coordinates in , and each packagejar
in the warehouse is uniquely represented since then. Regarding coordinates, the most familiar definition should come from plane geometry. In a plane coordinate system, coordinates (x, y) can uniquely identify a point on the plane.坐标
In real life, we can also regard the address as a kind of coordinates. Information such as provinces, cities, counties, townships, and villages can uniquely identify an address.
2.1 Composition of coordinates
The coordinates of maven are composed of groupId
, artifactId
, version
, packaging
and classifier
these tags together, as the simplest dependency as follows:
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-all</artifactId>
<version>1.7.1</version>
</dependency>
These jar packages formed by each organization or individual, that is, components, are uniquely represented in the above coordinate form when stored in the maven warehouse, and it is impossible to have components with the same coordinates.
2.2 Introduction of tags
groupId
: org
The beginning means a non-profit organization, com
the beginning means a commercial organization, and cn
the beginning means a Chinese community (for example, the famous hutool
toolkit is cn
the beginning).
Usually groupId
three paragraphs. The first paragraph is the beginning of the above, the second paragraph represents the company or organization, and the third paragraph represents the project name (the third paragraph is sometimes absent, but I think the clearest one should have a third paragraph).
artifactId
That is, jar
the package name, which is required.
version
That is, it corresponds to the version of the current jar
package, because jar
the package is also a small project maintained by an organization or company, and it must be constantly iterated, requiring version management. The specific version will be discussed separately in the next section.
packaging
Divided into jar
, war
, pom
.
jar
Everyone knows the package. Generally, the dependencies we quote are alljar
packages, andspringboot
the default startup project is alsojar
a package.war
The package needs to be placed in the container to start (nowspringboot
it can also be changed towar
a package and started directlyjava -jar
.);pom
If so, such as making a parent-child project structure, or declaring a unified reference.
3. maven repository
坐标
It corresponds to individual jar
packages, and these package files maven
are managed uniformly through the warehouse . Imagine yourself as a world, all organizations and individuals put into the world , that is, components, all adopt the form of expression to lock to the only component. Each belongs to a coordinate point in the world.jar
maven仓库
jar
坐标
jar
maven
maven
A set of rules is defined: any component in the world can use maven坐标
a unique identifier.
3.1 maven warehouse classification
There are warehouses 本地仓库
and 远程仓库
warehouses. Which 远程仓库
is divided into 中央仓库
, 私服仓库
, 其他公共仓库
. Probably as shown below:
- Private server, because there is
jar
a situation of developing its own package, it cannot be released to the public network. In this case, it is necessary to create a private server by itself, which is generally the warehouse manager that is commonly used nownexus
. - The central warehouse, that is,
Maven
its own official warehouse, most of the dependencies that can be named now, will be released in the central warehouse, and other warehouses are basically synchronized based on the central warehouse. - For other public warehouses, because
中央仓库
the download is generally slow, there are also阿里云
open public warehouses in China that can be downloaded. - Local warehouse, that is, the maven warehouse set up on your computer. When using maven, you will first obtain it from the local warehouse. If the local warehouse does not exist, you will find it from the company’s private server. If you do not have it on the private server, you will configure it according to the private server. The external network warehouse to synchronize.
3.2 maven download dependency process
As shown in the figure below, we specifically describe the process of relying on downloading during the development of the Maven project.
As you can see from the picture above, when the project is loaded for the first time, it will first go to the local warehouse to find it, and then go to the private server to find it. If it finds it, it will be synchronized to the local warehouse. If it cannot be found, it will rely on the private server Search the external network warehouse configured on the Internet in turn until you find it. If you can't find it, then there is nothing.
4. nexus private server
Let’s take a look at some information on the company’s private server interface. Of course, every company is different, as long as you know what there is probably.
When developing in the company, the general leader will ask you to connect to a specific maven
address, then you can copy them and visit the following on the browser. Generally, you can access things, but some are simple tree structures, and some are nexus UIs. interface. As follows:
Some delete the path, such as the above picture, http://www.xxxx.com/nexus
after deleting the path behind, the following page may appear:
If UI
the interface can appear, if you have an account, you can log in to see some things in the warehouse. Because ordinary developers do not have permission to log in to this page, you may not be able to log in with your account.
After successful login, you can see the following information:
You can probably understand nexus
what it is. In a word, it is a maven
warehouse manager specially used to build private servers. It mainly contains warehouses, and there are various corresponding configuration download dependencies. source address. Each warehouse has corresponding dependency package management, and you can upload dependencies, view dependency information and other operations in this UI interface.
5. Conclusion
It’s mainly text, which may seem a bit strenuous, but mainly to understand and understand 仓库
these 坐标
two things. I will talk about them separately in the next article version
, and they are also the most interesting to me. So I took it out and wrote it separately, hoping not to be too disappointed.
Summary and understanding of the next maven version number version