Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand and master Maven

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to understand and master Maven". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to understand and master Maven".

1. What is Maven?

At first glance, Maven seems to have a lot of things, but in short, Maven tries to apply patterns to the project's build infrastructure to improve understanding and productivity by providing a clear path to best practices. Maven is essentially a project management and understanding tool, so it provides a way to help management:

Construction

Document

Report

Dependence

Supply chain management system

Publish

Distribution

2.Maven 's philosophy

Maven is generally considered by many to be a build tool. Many people who come to Maven are initially familiar with Ant, so it's a natural association, but Maven is more than just a build tool, not just a replacement for Ant. Maven is completely different from Ant. Ant is just a toolkit, while Maven is about the application of patterns to achieve the infrastructure of display visibility, reusability, maintainability and understandability.

Without these features, multiple people are likely to work together efficiently on the project. Without visibility, an individual is unlikely to know what another person has accomplished, so it is likely that useful code will not be reused. It is difficult to create a maintainable system without reusing the code. When everyone is constantly trying to find all the different points that make up the project, it is difficult for anyone to understand the whole project. As a result, you will eventually encounter an island effect, a decline in shared knowledge, and a corresponding degree of frustration among team members. This is a natural effect when the process does not work in the same way for everyone.

Maven was born out of a very practical desire to work at Apache in the same way. As a result, developers can move freely between these projects and clearly understand how they work by understanding how one of them works.

If developers take the time to understand how a project is built, they don't have to go through this process again when they move on to the next project. The same idea extends to testing, generating documentation, generating metrics and reports, testing and deployment. All projects have enough of the same characteristics to understand that Maven attempts to take advantage of its general project management approach. At a high level, all projects need to be built, tested, packaged, documented, and deployed. Of course, there are unlimited changes in each of these steps, but this change still occurs within the scope of a clearly defined path, and Maven tries to present that path to everyone in a clear way. The easiest way to identify the path is to provide people with a set of patterns that can be shared by anyone in the project.

Ralph Johnson and Don Roberts' favorite sentence in the Evolutionary Framework Model:

People develop abstractions by generalizing them from concrete examples. Without actually developing and running the system, every attempt to determine the correct abstraction on paper is doomed to failure. No one is that smart. A framework is a reusable design, so you can develop it by looking at what it is supposed to be. The more examples you see, the more generic your framework will be.

I really don't know what the end result will be. I just know that there must be a better way. But first I know I want to:

A model of the project so that you can find everything related to the project in one place

A standard directory structure, so you don't have to look for libraries, resources, and documents.

3. Give examples to understand

As a matter of fact, all of the above are official languages, and it is more appropriate for people like me to give examples:

If you are developing two Java projects under Eclipse and call them An and B, and some of the functions in Project A depend on some classes in Project B, how do you maintain this dependency?

Very simple, this is not the same as when we wrote the program before, which classes in which project we need to use, that is, using the functional code written by others, we can import the jar package. So this is also the case here, you can type the B project into a jar package, and then import the B jar file under the Library of the A project, so that the A project can call some classes in the B project.

This has several defects. If you find the bug in B during the development process, you must modify the B project, repackage B and recompile the A project. After completing the development of the A project, in order to ensure the normal operation of A, you need to rely on B (just as you have to rely on another jar when using a jar package). Two solutions, the first, choose to package B into A. Second, release B, and when others need to use A, tell the developer that if you want to use A, you must import the Bjar package. Both of them are troublesome, and the former may cause a waste of resources (for example, developers may be developing other projects that rely on B, which is already stored locally, and if you import A's jar package, you will have two B's jar). The latter is something we often encounter, and it is very troublesome to find all kinds of jar packages (it is different with maven).

If we develop a project, or do a small demo, such as using the SSH framework, then we must find out dozens of dependent jar packages used by the SSH framework in turn and import them manually, which is super tedious.

The description of the above two problems, in fact, belong to the problem of project-to-project dependency [Project A uses all jar of SSH, that is to say, Project A relies on SSH]. It is tedious and inconvenient to solve manually, so use maven to help us manage.

The core function of Maven is to reasonably describe the dependencies between projects. In popular terms, it is to obtain the jar package through the configuration of the pom.xml file, rather than adding the jar package manually, and here the pom.xml file is familiar to people who have learned a little bit of maven. How can you get the jar package through the configuration of pom.xml? where does the pom.xml configuration file come from? And so on, we need to figure out similar problems, if you need to use pom.xml to get the jar package, then the project must first be a maven project, maven project can think of it this way, that is, the java project and web project are wrapped with a layer of maven, in essence, java project or java project, web project or web project, but after the package maven, you can use some of the functions provided by maven (add jar package through pom.xml).

So, according to the description in the previous paragraph, our ultimate goal is to learn how to configure pom.xml to get the jar package we want. Before that, we must understand how to create a maven project, what is the structure of the maven project, what is the difference from the ordinary java,web project, and how to configure pom.xml to get the corresponding jar package, and so on.

The compilation of jar package for pom.xml to get junit

Why can you locate a jar package through the groupId, artifactId, and version attributes?

Add the above pom.xml file belongs to A project, then A project must be a maven project, through the above three properties can find the corresponding version of junit jar package, then junit project must also be a maven project, junit maven project in the pom.xml file will have three identifiers, such as the following figure, and then other maven projects can find the junit project jar package through these three properties. Therefore, each maven project created will be required to write these three attribute values.

After reading the above, and then take a look at the pictures I have drawn, I guess I can understand it very much:

Thank you for your reading, the above is the content of "how to understand and master Maven". After the study of this article, I believe you have a deeper understanding of how to understand and master Maven, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report