Installing Maven
- Download the installation package and install Maven to a directory (for example, /opt/tools/installed/).
1 2 3
wget https://archive.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz tar -zxf apache-maven-3.6.3-bin.tar.gz mv apache-maven-3.6.3 /opt/tools/installed/
- Modify the Maven environment variables.
- Open the profile file.
1vim /etc/profile - Press i to enter the insert mode and add the following content to the end of the /etc/profile file:
1 2
export MAVEN_HOME=/opt/tools/installed/apache-maven-3.6.3 export PATH=$MAVEN_HOME/bin:$PATH
- Press Esc, type :wq!, and press Enter to save the file and exit.
- Open the profile file.
- Make the environment variables take effect.
1source /etc/profile
- Check whether the configuration takes effect.
1mvn -v
- Modify the local repository path and remote repository in the Maven configuration file.
Configuration file path: /opt/tools/installed/apache-maven-3.6.3/conf/settings.xml
The default local repository directory is ~/.m2/. If you want to change the directory, modify the localRepository tag. You do not need to modify this parameter unless otherwise specified.
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 7 8 9 10 11 12 13 14 15 16
<mirrors> <id>mirrors.huaweicloud.com</id> <url>https://mirrors.huaweicloud.com/kunpeng/maven</url> <name>mirrors huaweicloud com</name> <snapshots> <enabled>false</enabled> </snapshots> </mirrors> <mirrors> <id>repository.huaweicloud.com</id> <url>https://mirrors.huaweicloud.com/repository/maven</url> <name>repository huaweicloud com</name> <snapshots> <enabled>false</enabled> </snapshots> </mirrors>
If a proxy is used, add the proxy configuration to the settings.xml file. The details are as follows:
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>
Parent topic: Configuring the Compilation Environment