centos7安装maven

首先在官网下载:http://maven.apache.org/download.cgi

apache-maven-3.6.2-bin.tar.gz

下载后用tar命令解压,我解压在/data目录下

编辑环境变量 vim /etc/profile    添加

#java环境变量
JAVA_HOME=/data/jdk1.8.0_212
JRE_HOME=/data/jdk1.8.0_212/jre
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
export JAVA_HOME JRE_HOME PATH CLASSPATH
#maven环境变量
export MAVEN_HOME=/data/apache-maven-3.6.2
export PATH=${MAVEN_HOME}/bin:${PATH}

保存后更新环境变量source /etc/profile

执行:mvn -v

[root@centos7641 data]# mvn -v
Apache Maven 3.6.2 (40f52333136460af0dc0d7232c0dc0bcf0d9e117; 2019-08-27T23:06:16+08:00)
Maven home: /data/apache-maven-3.6.2
Java version: 1.8.0_212, vendor: Oracle Corporation, runtime: /data/jdk1.8.0_212/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-957.27.2.el7.x86_64", arch: "amd64", family: "unix"

然后修改一些maven的配置文件:/data/apache-maven-3.6.2/conf/settings.xml

首先添加本地仓库目录:

<localRepository>/data/mvnRepository</localRepository>

阿里云镜像地址:

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


profile:

<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>


要发表评论,您必须先登录