我要评分
获取效率
正确性
完整性
易理解

Installing Maven

  • Maven is an open source Java project of Apache. It is a project management tool that can be used to build and manage Java projects.
  • You are not advised to run the ./mvnw clean install command to build the project because even if Maven has been installed, a Maven version will be automatically downloaded after you run this command. To download a specified Maven version, for example, apache-maven-3.5.0-bin.zip:
    grep -nr https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
    vi .mvn/wrapper/maven-wrapper.properties
  • You are advised to run the mvn clean install command to build a project using the installed Maven version. You can also run the mvn clean install -DskipTests=true command to skip test cases and directly build a project.
  1. Download the Maven installation package.
    1. Download address: https://archive.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
    2. Copy it to the /home directory on the server.
    If the server is connected to the Internet, you can run the wget command to download the installation package.
    1
    2
    cd /home
    wget https://archive.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz --no-check-certificate
    
  2. Decompress the installation package.
    1
    tar -zxvf apache-maven-3.6.3-bin.tar.gz
    
  3. Install Maven in the specified directory, for example, /opt/.
    1
    mv apache-maven-3.6.3 /opt/
    
  4. Configure the Maven environment variables.
    1. Open the profile file.
      vim /etc/profile
    2. Add the content of the corresponding system to the file.
      export MAVEN_HOME=/opt/apache-maven-3.6.3
      export PATH=$MAVEN_HOME/bin:$PATH
    3. Press Esc, type :wq!, and press Enter to save the file and exit.
    4. Make the environment variables take effect.
      1
      source /etc/profile
      
    5. View the environment variables.
      echo $MAVEN_HOME
      echo $PATH

  5. View the Maven version.
    1
    mvn -v
    

  6. Modify the Maven configuration file.
    1. Open the configuration file.
      vim /opt/apache-maven-3.6.3/conf/settings.xml
    2. Configure the local repository.

      The default address of the local repository is ${user.home}/.m2/repository. If you log in as the root user, the local repository path is /root/.m2/repository.

    3. Configure the remote HUAWEI CLOUD (find <mirrors> and <profiles> and add the corresponding content):
      <mirrors>
               <mirror>
                      <id>huaweicloud</id>
                      <mirrorOf>*</mirrorOf>
                      <url>https://mirrors.huaweicloud.com/repository/maven/</url>
               </mirror>
      </mirrors>
      <profiles>
             <profile>   
               <id>repoId1</id>    
               <activation>     
               <activeByDefault>true</activeByDefault>   
               </activation>    
               <repositories>        
               <repository>       
                <id>huaweimaven</id>        
                <name>huaweimaven</name>        
                <url>https://mirrors.huaweicloud.com/kunpeng/maven</url>        
                <releases>        
                     <enabled>true</enabled>     
                </releases>        
                <snapshots>        
                     <enabled>false</enabled>      
                </snapshots>     
               </repository>   
               </repositories> 
             </profile>
      </profiles>

    4. Configuring a network proxy.

      If a proxy is used to access the Internet, you need to configure the network proxy (set host, port, username, and password based on your requirements):

      <proxies>
         <proxy>
           <id>my-proxy</id>
           <active>true</active>
           <protocol>https</protocol>
           <host>xxx</host>
           <port>xxx</port>
           <username>xxx</username>
           <password>xxx</password>
           <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
         </proxy>
         <proxy>
           <id>my-proxy1</id>
           <active>true</active>
           <protocol>http</protocol>
           <host>xxx</host>
           <port>xxx</port>
           <username>xxx</username>
           <password>xxx</password>
           <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
         </proxy>
      </proxies>
    5. Press Esc, type :wq!, and press Enter to save the file and exit.