centos配置maven环境

发布于2022-04-24  2,006次阅读


1.先去官网下载mavenv包

https://maven.apache.org/download.cgi

选择这个包下载

2.下载完成之后上传到服务器

3.移动并解压

mv apache-maven-3.8.5-bin.tar.gz /usr/local/

cd /usr/local/

tar -zxvf apache-maven-3.8.5-bin.tar.gz

4.配置环境变量

vim /etc/profile

// 在后面加上

#Maven
export MAVEN_HOME=/usr/local/apache-maven-3.8.5
export PATH=$PATH:${MAVEN_HOME}/bin

5.保存生效和测试

source /etc/profile

mvn -v

# 出现如果结果就是成功了
Maven home: /usr/local/apache-maven-3.8.5
Java version: 1.8.0_321, vendor: Oracle Corporation, runtime: /usr/local/java/jdk1.8.0_321/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-1160.45.1.el7.x86_64", arch: "amd64", family: "unix"

6.常见错误

The JAVA_HOME environment variable is not defined correctly,
this environment variable is needed to run this program.

出现以上错误是JAVA_HOME路径不对

修改变量环境中的JAVA_HOME路径就可以

vim /ect/profile

# 检查java环境变量
#Java Env
export JAVA_HOME=/usr/local/java
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:${JAVA_HOME}/bin

# 发现JAVA_HOME错误 修改为真实路径
export JAVA_HOME=/usr/local/java/jdk1.8.0_321

#根据自己服务器目录路径来修改

#修改后保存

source /ect/profile


# 使配置生效

# 测试

mvn -v


#结果

Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0)
Maven home: /usr/local/apache-maven-3.8.5
Java version: 1.8.0_321, vendor: Oracle Corporation, runtime: /usr/local/java/jdk1.8.0_321/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-1160.45.1.el7.x86_64", arch: "amd64", family: "unix"

 


  • 微信或支付宝

道,可道,非常道;名,可名,非常名。