Maven download installation and its configuration

Maven download installation and its configuration

1. Introduction to Maven

insert image description here

Maven is a popular build tool and dependency management tool for managing builds, releases, and dependencies of Java projects. It provides a standardized project structure, build life cycle, and plug-in system that make it easier for developers to build and manage complex Java projects.

Here are some key concepts of Maven:

  1. Project Object Model (POM): At the heart of a Maven project is an XML file called the POM. POM files describe information such as project metadata, dependencies, build configurations, and plugins.

  2. Dependency management: Maven can automatically download and manage the dependent libraries required by the project. By declaring dependencies in the POM file, Maven can obtain the required dependencies from the central warehouse or other remote warehouses, and automatically resolve dependency conflicts.

  3. Build lifecycle: Maven defines a standard set of build phases called the build lifecycle. These lifecycles include clean, compile, test, package, deploy, etc. phases that developers can trigger by executing specific build commands.

  4. Plug-in: Maven's plug-in system provides a rich function extension mechanism. Plugins can be used to perform specific build tasks, such as compiling code, running tests, generating documentation, and more. Maven itself provides many commonly used plug-ins, and also supports the development of custom plug-ins.

  5. Warehouse management: Maven uses warehouses to store dependencies and plugins required for building. It includes two types of local warehouses and remote warehouses. The local repository is located on the developer's local computer and is used to store downloaded dependent libraries and plugins. The remote warehouse can be a central warehouse or other custom remote warehouses, which are used to obtain the dependent libraries and plug-ins of the project.

The steps to use Maven usually include the following aspects:

  1. Install Maven: First, you need to install Maven on your computer, download and install the Maven distribution, and set the corresponding environment variables.

  2. Create a project: Create a new Maven project using Maven's command-line tools or the Maven Integrated Development Environment (IDE) plugin. This will generate a project directory structure containing the POM file.

  3. Edit the POM file: Edit the POM file according to the needs of the project, including adding dependencies, configuring build plugins, and setting other project information.

  4. Build the project: Execute Maven commands in the project directory, such as mvn clean install. This triggers Maven's build lifecycle, executing the appropriate build phases and plugin tasks, such as compiling sources

2. Download and install Maven

Go to the official website: https://maven.apache.org/download.cgi
to download the latest version, but it is recommended to download version 3.8 and use more

2.1, the latest

[When this blog post was released, the corresponding latest version was 3.9.3], if you download the latest version, just download it directly.
insert image description here

2.2, old version 3.8

Scroll down the page: Find more versions of Maven 3 archives Maven 3
My Maven version is 3.8.5, just download as needed, take 3.8.5 as an example
insert image description hereinsert image description here
insert image description here

insert image description here

Click to download the installation package
, and the installation package can be decompressed to the specified path [note that there is no Chinese], mine is the D drive, under the Maven folder, and at the same time,
create a new warehouse name [jarwarehouse] under the Maven folder, just customize it, but you have to know what it is! ! !
insert image description here
It looks like this after downloading [There may be differences, the problem is not big]
insert image description here

3. Maven environment configuration

3.1. Configuration

My Computer/This Computer--"Right-click Properties--"Advanced System Settings--"Environment Variables--"System Variables--"New--"OK/Save
orWin11 system: Settings--"System Information--"Advanced System Settings--"Environment Variables--"System Variables--"New--"OK/Save

  • The variable name is MAVEN_HOME
  • The variable value is the installation path of Maven.
    insert image description here
    Scroll down to find Path, double-click to enter, and create a new one.
    insert image description here

Fill in the new content: %MAVEN_HOME%\bin
can be filled in according to my screenshot, I filled it in this way
insert image description here

3.2. Verification

Win + R, enter cmd to open the command line window (dos window), enter the command to verify whether the Maven download configuration is correct

mvn -version

insert image description here

3.3, Configure the local warehouse

The folder where the warehouse has been built above [jarwarehouse]
1. Open the conf/settings.xml file in the apache-maven-3.8.5 directory
insert image description here/2, 2.add code

<localRepository>D:/Maven/jarwarehouse</localRepository>

insert image description here3. Configure Aliyun remote warehouse to improve access efficiency

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

It is recommended to use Notepad++ or Sublime editor to view to better distinguish
insert image description here

4. Enter the command at the command prompt: mvn help:system
Execute the mvn help:system command for the first time, and Maven related tools will automatically help us download the default or updated various configuration files and class libraries (jar packages) from the Maven central warehouse to the Maven local warehouse:

输入命令:mvn help:system

There are a lot of bread in my folder, because Maven installation is quite a long time ago, and I downloaded more packages for my own study and project. The folder will increase when I enter the command for the first time and compare it with the initial download and decompression.

insert image description here

After downloading various files, the mvn help:system command will print out all Java system properties and environment variables, and BUILD SUCESS will appear after the final success

insert image description here

4. Use Maven

4.1. Maven common commands

Maven provides many commonly used commands, the following are some common Maven commands and their functions:

  1. mvn clean: Cleans up the project, removing generated object files and build artifacts.

  2. mvn compile: Compile the project source code.

  3. mvn test: Run the project's test code.

  4. mvn package: Package project, which packages the compiled code into a deployable format such as JAR, WAR or EAR.

  5. mvn install: Install the project build result to the local warehouse for use by other projects.

  6. mvn deploy: Publish the project build results to the remote warehouse for use by other developers or projects.

  7. mvn clean install: Perform a cleanup operation and install the project to the local repository.

  8. mvn clean package: Performs a cleanup operation and packages the project.

  9. mvn clean test: Performs cleanup operations and runs the project's tests.

  10. mvn clean compile: Performs cleanup operations and compiles the project source code.

  11. mvn dependency:tree: Displays the project dependency tree, including details of all direct and indirect dependencies.

  12. mvn dependency:resolve: Parse the project dependencies, download and install the dependent libraries required by the project.

  13. mvn dependency:purge-local-repository: Clean up all dependencies in the local warehouse for re-downloading.

  14. mvn clean install -DskipTests: Performs cleanup operations, installs the project, and skips running tests.

These are just examples of some common Maven commands. Maven also has many other commands and plugins available. You can choose the appropriate command to perform corresponding tasks such as building, testing, and dependency management according to the needs and specific conditions of the project. mvn --helpA more detailed command list and description can be obtained by running the command or by referring to the Maven documentation.

4.2. Use in IDEA

1. Introduce warehouse and configuration files in the settings
insert image description here
2. Introduce dependencies in the project pom.xml file for use
Relevant dependencies can be searched and used on this website: Maven dependencies
insert image description here

3. Visualization tools are cheap to use
insert image description here

Guess you like

Origin blog.csdn.net/AN_NI_112/article/details/131478703