最近电脑重装了系统,各种环境重新配置了一遍
配置maven的时候出现了一点状况
输入mvn -v之后总是报一个提示
- The JAVA_HOME environment variable is not defined correctly
- This environment variable is needed to run this program
- NB: JAVA_HOME should point to a JDK not a JRE
首先输入
vim ~/.bash_profile
进入环境变量的配置
然后将下面的复制粘贴进去
文件位置 ~/.bash_profile
- # 设置 JDK 7
- export JAVA_7_HOME=`/usr/libexec/java_home -v 1.7`
- # 设置 JDK 8
- export JAVA_8_HOME=`/usr/libexec/java_home -v 1.8`
-
- #默认JDK 8
- export JAVA_HOME=$JAVA_8_HOME
-
- #alias命令动态切换JDK版本
- alias jdk6="export JAVA_HOME=$JAVA_6_HOME"
- alias jdk7="export JAVA_HOME=$JAVA_7_HOME"
- alias jdk8="export JAVA_HOME=$JAVA_8_HOME"
然后输入
source .bash_profile
使得刚刚配置的环境变量生效
之后再在终端中输入
- mvn -v
- Maven home: /Library/dev/apache-maven-3.6.3
- Java version: 1.8.0_151, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/jre
- Default locale: zh_CN, platform encoding: UTF-8
- OS name: "mac os x", version: "10.14.6", arch: "x86_64", family: "mac"
成功显示maven的信息