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, jarmore and more packages are used in the project. jarIn 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

NacosService registration discovery
WebFramework environment
③ Diagram template technology Thymeleaf
In the end 106 jarpackages were imported

And if you use Mavento import these jarpackages, 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

jarThe 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.

  1. jarpackage name
  2. jarpackage version
  3. jarThe specific details of the package

MavenAfter , the corresponding jarpackage can be downloaded automatically, which is convenient, fast and standardized.

1.3 Dependencies between jar packages

jarThe 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, jarthere may be conflicts between packages. It further increases the difficulty for us in the process of using jarthe package .

Here are the dependencies between jarthe packages :
insert image description here

In fact, the dependencies between jarpackages 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 Mavenwhen , 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 develop IDEAwith , the build is IDEAdone for us.

2.2 It still needs to be built after leaving the IDE environment

insert image description here

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.

insert image description here

1. Build

JavaIn project development, construction refers to the process of using raw materials to produce a product .

⭕ Raw materials

  1. Javasource code

  2. Based HTMLon Thymeleafthe file

  3. picture

  4. configuration file

⭕ Products

  1. 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: Javacompile the source program into a *.classbytecode 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.

  1. JavaEngineering: jarpackage
  2. WebEngineering: warpackage

● Installation: Store the jar package or war package generated by a Maven project into the Maven warehouse
● Deployment

  1. Deploy jarpackage : jardeploy a package to the Nexusprivate server
  2. Deploy warpackage : Deploy the package to the server with the help of the relevant Mavenplugin (for example )cargowarTomcat

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:

  1. junit-4.12relyhamcrest-core-1.3
  2. thymeleaf-3.0.12.RELEASErelyognl-3.1.26
  3. ognl-3.1.26relyjavassist-3.20.0-GA
  4. thymeleaf-3.0.12.RELEASErelyattoparser-2.0.5.RELEASE
  5. thymeleaf-3.0.12.RELEASErelyunbescape-1.1.6.RELEASE
  6. thymeleaf-3.0.12.RELEASErelyslf4j-api-1.7.26

⭕ Specific problems to be solved in dependency management:

jarDownloading of packages: MavenAfter , jarthe packages will be downloaded from the standard remote warehouse to the local
. jarDependencies between packages: automatically completed through the transitivity of dependencies
. jarConflicts between packages: By adjusting the configuration of dependencies, some jarpackage will not be imported

3. The working mechanism of Maven

insert image description here

Guess you like

Origin blog.csdn.net/weixin_52533007/article/details/125323264