Introduction to the basic concepts of maven

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 maventhis 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

  mavenTranslated 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")
  mavenThrough the passage 约定, major companies will jarprepare 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 jarthe package, and it is guaranteed 源码与依赖分离, 多个项目共用依赖saving a lot of time wasted in building, and at the same time, it can have mavensome help from rich plug-ins.

2. maven coordinates

  mavenThere 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.坐标

insert image description here

  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, packagingand classifierthese 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: orgThe beginning means a non-profit organization, comthe beginning means a commercial organization, and cnthe beginning means a Chinese community (for example, the famous hutooltoolkit is cnthe beginning).
  Usually groupIdthree 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).
  artifactIdThat is, jarthe package name, which is required.
  versionThat is, it corresponds to the version of the current jarpackage, because jarthe 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.
  packagingDivided into jar, war, pom.

  • jarEveryone knows the package. Generally, the dependencies we quote are all jarpackages, and springbootthe default startup project is also jara package.
  • warThe package needs to be placed in the container to start (now springbootit can also be changed to wara package and started directly java -jar.);
  • pomIf so, such as making a parent-child project structure, or declaring a unified reference.

3. maven repository

  坐标It corresponds to individual jarpackages, and these package files mavenare 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坐标jarmaven

  mavenA 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:
insert image description here

  • Private server, because there is jara 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 now nexus.
  • The central warehouse, that is, Mavenits 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.
insert image description here

   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 mavenaddress, 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:
insert image description here
   Some delete the path, such as the above picture, http://www.xxxx.com/nexusafter deleting the path behind, the following page may appear:
insert image description here
   If UIthe 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:
insert image description here
   You can probably understand nexuswhat it is. In a word, it is a mavenwarehouse 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

Guess you like

Origin blog.csdn.net/wohaqiyi/article/details/119235116