Perhaps you are running on a JRE rather than a JDK?

粗暴解决maven: Perhaps you are running on a JRE rather than a JDK? 问题

首先执行mvn -v 看到如下输出

Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-25T03:49:05+08:00)
Maven home: /usr/local/Cellar/maven/3.5.3/libexec
Java version: 1.8.0_221, vendor: Oracle Corporation
Java home: /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
Default locale: zh_CN, platform encoding: UTF-8
OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"

此处我们找到 Maven Home=/usr/local/Cellar/maven/3.5.3/libexec

访达 Command+shift + G输入/usr/local/Cellar/maven/3.5.3/bin, 我们来到maven安装目录,在bin目录下找到mvn文件, 用文本工具(如sublime)打开
发现如下代码

JAVA_HOME="${JAVA_HOME:-$(/usr/libexec/java_home)}" exec "/usr/local/Cellar/maven/3.5.3/libexec/bin/mvn" "$@"

可以发现这里maven通过系统命令获取javahome来执行,

我们将javahome替换成我们的jdk路径:

JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home exec "/usr/local/Cellar/maven/3.5.3/libexec/bin/mvn" "$@"

完成编辑 保存mvn

再次执行 发现java home 已经是jdk了,重新编译,成功。

$ mvn -v
Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-25T03:49:05+08:00)
Maven home: /usr/local/Cellar/maven/3.5.3/libexec
Java version: 1.8.0_111, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"

你可能感兴趣的:(Perhaps you are running on a JRE rather than a JDK?)