Maven from entry to mastery

Insert picture description here

What is Maven? What problems can Maven solve? ? What are the advantages of Maven? How to use Maven? How does IDEA build Maven project quickly, this article takes you to quickly understand Maven

What is Maven

What is Maven

The correct pronunciation of Maven is [ˈmevən], not "horse plague" and whatever. Maven is a colloquial word in the United States, which means expert and expert.
A more formal definition of Maven says this: Maven is a project management tool , which contains a project object model (POM: Project Object Model), a standard set , a project life cycle (Project Lifecycle), a dependency The management system (Dependency Management System) and the logic used to run the goals defined in the plugins in the lifecycle phases .

What problems can Maven solve

It can be explained in a more popular way. We know that project development is not just about writing code. During this period, it will be accompanied by various essential things to do. Here are a few feelings:
Insert picture description here
1. We need to refer to various jar packages, especially for larger projects. There are dozens or even hundreds of jar packages referenced. Every time a jar package is used, it needs to be manually introduced into the project directory, and it often encounters various jarring jar package conflicts and version conflicts.

2. We have worked hard to write a Java file, but an idiot computer that only understands 0 and 1 can't read it at all, and it needs to be compiled into binary bytecode. Fortunately, this work can be completed by various integrated development tools for us, and Eclipse, IDEA, etc. can compile the code on the fly. Of course, if you feel that your life is long, why not be extravagant, you can also use Notepad to type the code, and then use the javac command to compile one by one to make the computer play.

3. There is no bug-free code in the world. Computers like bugs just like people always like beautiful guys. In order to pursue beauty and reduce bugs, so after writing the code, we have to write some unit tests, and then run one by one to verify the quality of the code.

4. No matter how elegant the code is, it will be sold. We also need to integrate the code with various configuration files and resources, and finalize and package it. If it is a web project, we need to publish it to the server for destruction.

Imagine if there is now a tool that can free you from the tedious work above and can help youBuild projects, manage jar packages, compile code, help you automatically run unit tests, package, generate reports, and even help you deploy projects and generate Web sites, Will you be emotional? Maven can solve the problems mentioned above.

Examples of advantages of Maven

Earlier, through the Web stage project, to be able to run the project, you must add some jar packages that the project depends on to the project, otherwise the project cannot run. Imagine if there are ten projects with the same architecture, then we need to copy this jar package to ten different projects. Let's take a look at the size of a CRM project. CRM projects built using traditional Web projects are as follows: The
Insert picture description here
main reason is that the above WEB program needs to be run. We must copy the Jar packages needed for the project to the project directory, resulting in a large project. The same project, if we use the Maven project to build, will find that the overall project size will be much less. As shown below:
Insert picture description here
Summary:It can be preliminarily inferred that there must be no jar package in it. Continue to think about how can a project without jar package run?

Two classic roles of Maven

Maven dependency management

A core feature of Maven is dependency management. When we involve multi-module projects (containing hundreds of modules or sub-projects), managing dependencies becomes a difficult task. Maven demonstrated its high control over handling this situation. In traditional WEB projects, we must copy the jar packages that the project depends on to the project, which causes the project to become very large. So how does the maven project make few projects? The analysis is as follows:
Insert picture description here
Through analysis, it is found that the jar package is not directly imported into the project in the maven project, but the coordinates of the required jar package are added to the pom.xml file, which prevents the jar from being directly imported. When you need to use jar packages, just find the pom.xml file, and then use the coordinates in the pom.xml file to find a jar package specifically for "storage jar package" (maven warehouse) according to the coordinates to find these jar packages, Then take these jar packages to run. So the question comes first: "storage jar package warehouse" look like? Second: Is it very slow to read the coordinates in the pom.xml file and then find the jar package in the warehouse? Therefore, this method is not feasible!

The first question: what does the warehouse holding the jar packages look like? At this point, we will analyze the classification of the warehouse later, and will also take you to see what our local warehouse looks like.
The second problem: configure the coordinates of the jar package to be introduced through the pom.xml file, then read the coordinates and load the jar package into the warehouse, so that we can directly use the jar package, in order to solve the problem of slow speed in this process There is also the concept of indexing in maven. By establishing the index, the speed of loading the jar package can be greatly improved, making us think that the jar package is basically the same as the speed of reading it in the local project file. This process is like when we look up the dictionary. In order to speed up the search for the content, the directory in front of the book is like an index. With this directory, we can easily find the content. Similarly, with the index in the maven warehouse, we can think You can quickly find the jar package.

One-click project construction

Our projects often go throughCompile, test, run, package, install, deployWait for a series of processes. What is build? It refers to the entire process of compiling, testing, running, packaging, installing, and deploying the project to maven for management. This process is called build. One-click build refers to == the entire build process, using maven one command can easily complete the whole work. ==

The normalized Maven build process is as follows:
Insert picture description here
Let's take a look at the one-click running process of the Hello-Maven project. Through the command of tomcat: run , we found that the current project compilation, testing, and running have become very simple.

END! ! !
The next article introduces the use of Maven, a
long road, JAVA as a companion! ! !

Published 51 original articles · Like 163 · Visitors 10,000+

Guess you like

Origin blog.csdn.net/qq_43688587/article/details/105573032