错误显示:$mvn -version
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

// 错误显示:
$mvn -version
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

原因:jdk配置不规范

// 原因: javajdk配置不规范
$echo $JAVA_HOME
/usr/lib/jvm/java-11-openjdk-amd64/bin/java
// 修改:
$export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
$export PATH=$JAVA_HOME/bin:$PATH

再次查看mvn -version

$mvn -version
Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-05T03:00:29+08:00)
Maven home: /opt/apache-maven-3.6.1
Java version: 10.0.2, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-47-generic", arch: "amd64", family: "unix"

成功!
当然,这个修改只是临时的,当你关闭该终端,再打开时会再次遇到最开始的问题;建议永久性修改该配置 ( ~/.bashrc文件配置仅对当前用户有效 )

$vim ~/.bashrc
// 添加以下配置到文件末尾
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH

执行 source ~/.bashrc 即可
这样即使关闭终端也不会失效了

Logo

更多推荐