Maven installation and configuration tutorial

WeChat scan code to pay attention to this warm programmer

1 What is Maven

1.1 Overview of Maven

Maven is a project management tool that can automate the construction and dependency management of Java projects. Maven includes a project object model (Project Object Model), a set of standard collections, a project life cycle (Project Lifecycle), a dependency management system (Dependency Management System), and is used to run definitions in the life cycle phase (phase) The logic of the plugin goal. When you use Maven, you describe your project with a well-defined project object model, and Maven can then apply crosscutting logic from a set of shared (or custom) plugins.

1.2 Common commands of Maven

Order explain
mvn compile compile source code
mvn deploy post project
mvn site A website that generates project-related information
mvn clean Clear build results in project directory
mvn package Generate jar according to the project
mvn install Install the jar in the local Repository
mvn archetype:generate Create a Maven project

(The above explanation comes from the Internet)

2 How to install Maven

2.1 Download Maven package

To download the Maven package, you can go directly to the Maven official website: https://maven.apache.org/

1. Open Maven official website, click Download to show you the latest version

2. You can download the latest version, just click apache-maven-xxx-bin.zip to download. You can also click archives to select other versions, as follows:

3. Here the author takes apache-maven-3.6.3 as an example, click 3.6.3/

4. Click binaries

5. Click on apache-maven-3.6.3-bin.zip

6. After the download is complete, decompress it to a certain drive letter (you can define where to put it)

2.2 Configure environment variables

1. My Computer/This Computer--"Right-click Properties--"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

For example, the author apache-maven-3.6.3 is under the D drive, the variable value is: D:\apache-maven-3.6.3

2. Verify whether the maven environment configuration is successful (press win+R to output cmd and pop up the command line window (dos window))

Enter the command: mvn -version

2.3 Configure local warehouse

1. Create a new folder repository under any drive letter (custom folder name). The author takes the D drive as an example, and the path of the new folder is: D:\repository

2. The notepad tool opens the conf/settings.xml file in the apache-maven-3.6.3 directory

3. Find the node localRepository, add the address of your own warehouse outside the comment and save the settings.xml file

2.4 Configure remote warehouse

1. The default remote warehouse is abroad. In order to improve access efficiency, the domestic Aliyun remote warehouse is usually used. Open the settings.xml file, find the mirrors label, copy the following code, and save it.

Note: Be sure to put it inside the mirrors tag

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

2. Verify whether the maven local warehouse and remote warehouse are configured successfully (press and hold win+R to output cmd and pop up the command line window (dos window))

Enter the command: mvn help:system

Execute the mvn help:system command for the first time, 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:

After downloading the various files, the mvn help:system command will print out all Java system properties and environment variables:

At this point, the Maven installation and configuration tutorial is over, it is not easy to create, thank you for reading.

Guess you like

Origin blog.csdn.net/qq_40625778/article/details/125229241