下载
解压
tar -zxvf apache-maven-3.6.3-bin.tar.gz -C /opt/
环境变量
vi /etc/profile
输入
export MAVEN_HOME=/opt/apache-maven-3.6.3
export PATH=$PATH:$MAVEN_HOME/bin
应用环境变量
source /etc/profile
验证是否安装成功
mvn -v
配置
vi /opt/apache-maven-3.6.3/conf/settings.xml
本地仓库位置修改:在<localRepository>标签内添加自己的本地位置路径
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
<localRepository>/data/mvnRepo</localRepository>
修改maven默认jdk版本:在<profiles>标签下添加一个<profile>标签,修改maven默认的JDK版本
<profile>
<id>JDK-1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
添加国内镜像源:添加<mirrors>标签下<mirror>,添加国内镜像源
<!-- 阿里云仓库 -->
<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>
Eclipse下配置Maven
1.修改使用的maven配置,add后选择maven安装目录,勾选
2修改maven配置文件位置和本地仓库位置
其他:
1、找不到{user_home}.m2/repository目录,运行:
mvn help:effective-settings
2、引用外部jar包
将jar包放在src/main/webapp/WEB-INF/lib下
此处注意linux系统路径分隔符为/
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
<compilerArguments>
<extdirs>src/main/webapp/WEB-INF/lib</extdirs>
</compilerArguments>
</configuration>
</plugin>