MAVEN weapon: This article takes you to understand MAVEN and how to configure it

Foreword:

Powerful build tool - Maven. As an important part of the Java ecosystem, Maven provides developers with a simple and efficient way to build, manage and release Java projects. Whether it is a small project or a large enterprise application, Maven can help developers easily handle tasks such as dependency management, compilation, testing, and deployment.

 

Article Directory

Foreword:

 maven introduction:

The structure of maven:

Why do you need maven?

How to configure maven?

Summarize:


 maven introduction:

Maven is a popular Java build tool and project management tool developed and maintained by the Apache Software Foundation. It provides developers with a simple and powerful way to build, manage and publish Java projects . Based on the concept of Project Object Model (POM), Maven describes project dependencies, build configurations and other metadata through an XML file.

The main functions of Maven include dependency management , project construction , testing and deployment . By declaring project dependencies, Maven can automatically download required library files and manage their versions. It uses an agreed directory structure to manage project code, resource files, and configuration files, simplifying project organization and maintenance. Maven also provides a powerful and flexible plug-in system that can extend the functionality of the tool.

The structure of maven:

Maven's structure consists of a central repository and a private repository.

  1. Central warehouse : The central warehouse is the official warehouse of Maven, which stores a large number of open source Java libraries and plug-ins. It is the default warehouse. When Maven builds the project, Maven will automatically download the dependent libraries required by the project from the central warehouse. The central repository has broad coverage and contains many common development libraries and tools such as JUnit, Log4j, etc.

  2. Private warehouse : A private warehouse is a warehouse managed by a developer or an organization, in which specific dependent libraries and plug-ins for a specific project or organization are stored. A private repository allows developers to upload their own libraries and plugins to the repository and share them with team members or other developers.

Maven uses coordinates (Coordinates) to identify dependent libraries and plugins. Coordinates include information such as organization (Group), name (Artifact), version (Version), and are used to uniquely identify a library or plug-in in the warehouse.

When Maven builds a project, it will download the required dependent libraries and plugins from the central warehouse or private warehouse according to the dependency configuration in the project's POM file. If a dependency does not exist in the local warehouse, Maven will automatically download it from the remote warehouse and cache it in the local warehouse for subsequent use.

Private repositories are usually used to store internally developed libraries, third-party commercial libraries, or specific versions of libraries, etc. In order to use the dependent library in the private warehouse, the developer needs to configure the address of the private warehouse in the project's POM file.

Why do you need maven?

  1. Dependency management : Maven can automatically resolve project dependencies and manage their versions. It can automatically download and update the required library files, simplifying the dependency management process of the project.

  2. Project construction : Maven provides a set of standardized construction life cycle and agreed directory structure, making the project construction process more concise, standard and repeatable. Developers only need to define the POM file of the project, and Maven can automatically perform the required construction tasks.

  3. Plugin Ecosystem : Maven has a huge ecosystem of plugins that extend the functionality of the tool. Developers can perform various tasks through plug-ins, such as code inspection, test coverage analysis, static analysis, etc., thereby improving the quality and stability of the project.

  4. Team collaboration : Maven uses standardized configuration files and dependency management mechanisms, which simplifies the difficulty of team collaboration. Developers can share and reuse project configuration and dependency information to improve team development efficiency.

  5. Cross-platform : Since Maven is a Java-based tool, it is very cross-platform. Developers can use Maven to build and manage projects on different operating systems, such as Windows, Mac, and Linux.

  6. Community support : Maven is an open source project with a huge community support. Developers can access rich documentation, tutorials, and solutions from the community to solve problems and improve their skills.

How to configure maven?

1. First of all, we need to download the maven compressed package on the official website: Maven – Download Apache Maven

 For windows, download this version of the red arrow

 After downloading and decompressing, we can get such a file:

  • The bin directory contains executables that execute Maven commands, allowing you to run Maven tasks from the command line.
  • The boot directory contains Maven's startup class loader and related files, which help Maven to load and start correctly.
  • The conf directory contains Maven configuration files, where you can configure Maven's behavior and settings.
  • The lib directory contains Maven's dependent library files, including various plug-ins and components.

2. Make some changes to the settings in the conf directory:

(1). Add a private warehouse address to store libraries and plug-ins

We generally choose to create a folder under the statistics directory of the maven package, use the address of this folder as the address of the private warehouse, and add it to the setting in the conf folder

Open it with any compiler, here I choose VS code

Add the content as shown in the figure on line 55. The address in the red box is the folder of the private warehouse that you just determined.

(2). Add a mirror address to speed up the download of libraries and plug-ins from the central warehouse. Here we use Ali's mirror address

This operation is still in setting

 Here I write it out for everyone to paste and copy:

<mirror>
      <id>alimaven</id> 
       <name>aliyun maven</name> 
       <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
      <mirrorOf>central</mirrorOf>
</mirror>

When you're done, save your entries before closing the edit file.

3. Copy the address of the bin package in maven and add it to the PATH system environment variable.

 

 With such a set, we have successfully configured maven into our own computer. If you want to verify, you can use it in the cmd interface

mvn -v

authenticating

If a similar interface appears, the configuration is successful:

Summarize:

Maven is a powerful project management and build tool that provides an efficient development environment through dependency management, standard project structure, build life cycle, and plugin system. Configuring Maven to your computer only needs to download and set environment variables, and then you can take advantage of it to automatically resolve dependencies, manage project structures, perform build tasks, and add plugins. By using Maven, developers can focus on business development, improve the maintainability and reliability of the project, and it is a valuable tool regardless of the size of the project.

If my content is helpful to you, please like, comment and bookmark . Creation is not easy, everyone's support is my motivation to persevere!

 

Guess you like

Origin blog.csdn.net/fckbb/article/details/132314414