Rate This Document
Findability
Accuracy
Completeness
Readability

Installing Maven

  1. Download the installation package and install Maven to the specified directory (for example /opt/tools/installed/).
    1
    2
    3
    wget https://archive.apache.org/dist/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.tar.gz
    tar -zxf apache-maven-3.5.4-bin.tar.gz
    mv apache-maven-3.5.4 /opt/tools/installed/
    
  2. Modify the Maven environment variables.
    1. Open the /etc/profile file.
      1
      vi /etc/profile
      
    2. Press i to enter the insert mode and add the following content to the end of the file:
      1
      2
      export MAVEN_HOME=/opt/tools/installed/apache-maven-3.5.4
      export PATH=$MAVEN_HOME/bin:$PATH
      
    3. Press Esc, type :wq!, and press Enter to save the file and exit.
  3. Make the environment variables take effect.
    1
    source /etc/profile
    
  4. Check whether Maven is successfully installed.
    1
    mvn -v
    

    The installation is successful if information similar to the following is displayed:

  5. Modify the local repository path and remote repository in the Maven configuration file.
    1. Open the configuration file.
      1
      vi /opt/tools/installed/apache-maven-3.5.4/conf/settings.xml
      
    2. Press i to enter the insert mode. Add the following content to the <mirrors> tag to configure the remote repository (change the repository to the Maven repository that you have built. If the Maven repository does not exist, configure it based on the following example):
      1
      2
      3
      4
      5
      6
      <mirror>
        <id>huaweimaven</id>
        <name>huawei maven</name>
        <url>https://mirrors.huaweicloud.com/repository/maven/</url>
        <mirrorOf>central</mirrorOf>
      </mirror>
      

      The default local repository directory is ~/.m2/. If you want to change the directory to a specified one, modify the localRepository tag. You do not need to modify this parameter unless otherwise specified.

    3. Optional: If the compilation environment is not connected to the Internet, add the following proxy configuration to settings.xml:
       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      <proxies>
        <proxy>
          <id>optional</id>
          <active>true</active>
          <protocol>http</protocol>
          <username>Username</username>
          <password>Password</password>
          <host>Proxy server URL</host>
          <port>Proxy server port</port>
          <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
        </proxy>
      </proxies>
      
    4. Press Esc, type :wq!, and press Enter to save the file and exit.