安装maven

1、下载

wget https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz

2、创建maven目录

​ 在linux环境中创建maven目录,/usr/local/maven,将maven安装包上传至此目录中

mkdir /usr/local/maven

3、配置环境变量

vim /etc/profile

将下面这两行代码拷贝到文件末尾并保存

export MAVEN_HOME=/usr/local/src/apache-maven-3.6.3
export PATH=$PATH:$MAVEN_HOME/bin

重载环境变量

source /etc/profile

4、查看结果

mvn –v

[root@c1 ~]# mvn -v
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/local/src/apache-maven-3.6.3
Java version: 1.8.0_221, vendor: Oracle Corporation, runtime: /usr/java/jdk1.8.0_221-amd64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-1160.el7.x86_64", arch: "amd64", family: "unix"

5、修改配置

5.1 替换maven源,阿里云的源

打开maven配置文件,比如:

vim /usr/local/maven/apache-maven-3.6.1/conf/settings.xml

找到标签对,添加一下代码:

<mirror>
     <id>alimaven</id>
     <name>aliyun maven</name>
     <mirrorOf>central</mirrorOf>
     <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror> 

5.2 指定下载资源位置

<localRepository>/usr/local/maven/repository</localRepository>

5.3 指定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>
posted @ 2021-11-16 15:46  aitansi  阅读(17)  评论(0编辑  收藏  举报