Maven 是一个基于 Java 的工具,所以要做的第一件事情就是安装 JDK
Maven项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具。
下载安装
wget https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.tar.gz
tar -xf apache-maven-3.5.4-bin.tar.gz
mv apache-maven-3.5.4 /usr/local/
添加环境变量
vim /etc/profile
export PATH=/usr/local/apache-maven-3.5.4/bin:$PATH
source /etc/profile
验证
mvn -v
配置Maven仓库
因为maven默认使用的是美国官网仓库,在速度上会很慢,所以我们要配置自己的仓库.
1 配置阿里云maven仓库
vim /usr/local/maven/conf/settings.xml
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>*</mirrorOf>
<name>nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
2 创建maven私服 nexus
tar xf nexus-3.23.0-03-unix.tar.gz
mv nexus-3.23.0-03 /usr/local/
ln -s /usr/local/nexus-3.23.0-03 /usr/local/nexus
启动nexus
/usr/local/nexus/bin/nexus start
浏览器登录
192.168.2.41:8081
初始化用户名密码:
用户名 admin
密码 cat /usr/local/sonatype-work/nexus3/admin.password
配置仓库
把默认的中央仓库地址修改为阿里云maven地址
配置maven使用私服
vim /usr/local/maven/conf/settings.xml
servers标签内添加仓库认证信息 大概位置132行
<server>
<id>release</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
找到mirrors标签 大概170行
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://192.168.2.41:8081/repository/maven-public/</url>
</mirror>
URL私服地址获取
找到profiles标签 大概263行
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>central</id>
<url>http://192.168.2.41:8081/repository/maven-public</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://192.168.2.41:8081/repository/maven-public</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
激活 大概292行
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>