Maven (1): What is Maven?
foreword
This blogger will use CSDN to record the experience and knowledge he has personally gained and learned on the way to study software development. Interested friends can pay attention to the blogger! Perhaps a person can go fast alone, but a group of people can go farther!
1. Why learn Maven?
1. Maven as a dependency management tool
1.1 The size of the jar package
As we use more and more frameworks, or the framework is more and more encapsulated,
jar
more and more packages are used in the project.jar
In a project, it is very normal to use hundreds of packages in a module .
For example, in the following example, we only use three functions in the framework
SpringBoot
:SpringCloud
①
Nacos
Service registration discovery
②Web
Framework environment
③ Diagram template technologyThymeleaf
In the end 106jar
packages were imported
And if you use
Maven
to import thesejar
packages, you only need to configure three "dependencies":
<!-- Nacos 服务注册发现启动器 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- web启动器依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 视图模板技术 thymeleaf -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
1.2 The source of the jar package
⭕
jar
The official website of the technology this package belongs to. The official website usually has an English interface, and the structure of the website is different. Even after finding the download link, it is found that it needs to be downloaded through a special tool.
⭕ Third-party websites provide downloads. The problem is that it is not standardized, and various problems will arise during use.
jar
package namejar
package versionjar
The specific details of the package
⭕
Maven
After , the correspondingjar
package can be downloaded automatically, which is convenient, fast and standardized.
1.3 Dependencies between jar packages
jar
The packages used in the framework are not only huge in number, but also have intricate dependencies with each other. The complexity of dependencies has risen to a level that cannot be resolved manually by humans. In addition,jar
there may be conflicts between packages. It further increases the difficulty for us in the process of usingjar
the package .
Here are the dependencies between
jar
the packages :
In fact, the dependencies between
jar
packages are ubiquitous. If programmers have to sort out manually, it will undoubtedly increase the extremely high learning cost, and these tasks are of no help to realize business functions.However, there is almost no need to manage these relationships
Maven
when , and only a few adjustments can be made, which greatly reduces our workload.
2. Maven as a build management tool
2.1 Builds you haven't noticed
You can not use it
Maven
, but the build must be done. When we developIDEA
with , the build isIDEA
done for us.
2.2 It still needs to be built after leaving the IDE environment
3. Conclusion
⭕ Special tools are required to manage large-scale jar packages.
⭕ Executing build operations outside the IDE environment requires special tools.
2. What is Maven?
Maven is a tool maintained by the Apache Software Foundation that provides build and dependency management support for Java projects.
1. Build
Java
In project development, construction refers to the process of using raw materials to produce a product .
⭕ Raw materials
Java
source codeBased
HTML
onThymeleaf
the filepicture
configuration file
…
⭕ Products
- A project that can run on the server
⭕ The main links included in the construction process:
● Cleanup: delete the results of the previous build to prepare for the next build
● Compile:Java
compile the source program into a*.class
bytecode file
● Test: test the key points in the project to ensure The correctness of key points in the iterative development process of the project.
● Report: Record and display the test results in a standard format after each test.
● Packaging: Package a project containing many files into a compressed file for installation or deployment.
Java
Engineering:jar
packageWeb
Engineering:war
package● Installation: Store the jar package or war package generated by a Maven project into the Maven warehouse
● Deployment
- Deploy
jar
package :jar
deploy a package to theNexus
private server- Deploy
war
package : Deploy the package to the server with the help of the relevantMaven
plugin (for example )cargo
war
Tomcat
2. Dependence
⭕ If project A uses resources such as classes, interfaces, configuration files, etc. of project B, then we can say that project A depends on project B. For example:
junit-4.12
relyhamcrest-core-1.3
thymeleaf-3.0.12.RELEASE
relyognl-3.1.26
ognl-3.1.26
relyjavassist-3.20.0-GA
thymeleaf-3.0.12.RELEASE
relyattoparser-2.0.5.RELEASE
thymeleaf-3.0.12.RELEASE
relyunbescape-1.1.6.RELEASE
thymeleaf-3.0.12.RELEASE
relyslf4j-api-1.7.26
⭕ Specific problems to be solved in dependency management:
●
jar
Downloading of packages:Maven
After ,jar
the packages will be downloaded from the standard remote warehouse to the local
.jar
Dependencies between packages: automatically completed through the transitivity of dependencies
.jar
Conflicts between packages: By adjusting the configuration of dependencies, somejar
package will not be imported