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.
- Download the Maven installation package.
- Download address: https://archive.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
- 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
- Decompress the installation package.
1tar -zxvf apache-maven-3.6.3-bin.tar.gz
- Install Maven in the specified directory, for example, /opt/.
1mv apache-maven-3.6.3 /opt/
- Configure the Maven environment variables.
- Open the profile file.
vim /etc/profile
- 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
- Press Esc, type :wq!, and press Enter to save the file and exit.
- Make the environment variables take effect.
1source /etc/profile
- View the environment variables.
echo $MAVEN_HOME echo $PATH

- Open the profile file.
- View the Maven version.
1mvn -v
- Modify the Maven configuration file.
- Open the configuration file.
vim /opt/apache-maven-3.6.3/conf/settings.xml
- 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.

- 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>
- 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> - Press Esc, type :wq!, and press Enter to save the file and exit.
- Open the configuration file.
Parent topic: Configuring the Compilation Environment