Introduction to Maven and install Maven Install Maven under Windows

Maven project management

1. What is Maven?

Maven is a project management tool under Apache. It is developed by pure Java language, which can help us build and manage Java projects more conveniently. Project package management tool

Only Gradle is estimated to be comparable to Maven

2. Why use Maven

  1. Jar package management
    1.1 Obtain the standard Jar package from the Maven warehouse to avoid downloading the wrong Jar package by yourself.
    1.2 The local warehouse agrees to manage the Jar package to separate the Jar package from the project and reduce the size of the project
  2. Maven can be cross-platform Windows, Linux can be used
  3. Clear project structure
  4. Multi-project development, split the module into several projects, which is conducive to team development
  5. One-click build project

Three, Maven installation

As we all know that Maven is based on Java, so please make sure you have the correct Java environment before installing Maven

The official website states that Maven 3.3+ requires an environment above JDK1.7

  1. First download the latest Maven compressed package from the Apache-Maven official website

Maven download address

img

  1. View the downloaded structure directory

img

  1. Configure Maven environment variables

Right-click this computer> Properties> Advanced System Settings> Environment Variables below

img

  1. Select New (both new buttons are available)

img

  1. The variable name is M2_HOME (canonical writing)

  2. The variable value is your Maven path

  3. Click OK all the way

Four, test

Open a DOS command window

win + r 
输入 cmd

Type mvn -version

If the following result appears, the installation is successful!

img

Five, modify the configuration file

Find your Maven installation path

Open conf/setting.xml

  1. Set up MavenThe location of the local warehouse
<!--更改为你需要放置Maven仓库的位置  绝对路径 (也可以为相对路径)-->
<localRepository>E:\Environment\apache-maven-3.6.3\repository</localRepository>

img

  1. Set up a remote Maven repository

Scroll down to find the mirrors node

This node is the download address for configuring the remote warehouse. If Maven is not configured, the Jar package will be downloaded from the foreign warehouse or the download may fail.

You can see that the name of this node is mirrors, which means that multiple warehouses can be configured

<mirror>      
    <id>nexus-aliyun</id>    
    <name>nexus-aliyun</name>  
    <url>http://maven.aliyun.com/nexus/content/groups/public</url>    
    <mirrorOf>central</mirrorOf>      
</mirror>  
<!-- 
  如果你有私服 也可以在这里配置私服
  优先级为你配置的顺序

   <mirror>
            <id>nexus</id>
            <name>maven-public</name>
            <url>http://192.168.244.106:8081/repository/maven-public/</url>
            <mirrorOf>*</mirrorOf>
        </mirror>
 --> 

img

Six, the concept of Maven's three warehouses

1. The local warehouse maintains itself

2. The private server warehouse may be maintained by the company or by itself

3. The maintenance of the remote warehouse third-party team covers almost all jar packages on the market


Seven, Maven commonly used commands

command effect
mvn clean Clean up the compiled target directory
mvn compile Compile the code in main, not the code of test
mvn test-compile Compile the code in test and main
mvn test Run the code in the test
mvn package Bale
mvn install Publish the project to the local warehouse
mvn tomcat run One-click build project

Commands can be used in combination

such as

mvn clean compile

Author

YuFire

Guess you like

Origin blog.csdn.net/weixin_43420255/article/details/106414034