纵有疾风起
人生不言弃

mac系统 mvn打包报错:No compiler is provided in this environment. Perhaps you are running on a JRE

一、背景

最近将mac 升级到 Big Sur 版本,出现了个别奇奇怪怪的小问题。

系统升级后执行 mvn 命令,总是出现以下错误:

No compiler is provided in this environment. Perhaps you are running
on a JRE

截图如下:
mac系统 mvn打包报错:No compiler is provided in this environment. Perhaps you are running on a JRE插图

网上搜索了很多答案,基本都是说环境变量的问题,通过 java -version 检查了环境变量没啥问题。
折腾老半天没搞定,最终找到了解决方案,在这里将这个坑分享出来。

二、解决办法

2.1 下载并安装官方的 JDK

https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html

https://www.oracle.com/java/technologies/javase/javase9-archive-downloads.html

mac系统 mvn打包报错:No compiler is provided in this environment. Perhaps you are running on a JRE插图1

2.2 设置环境变量

vim ~/.bash_profile 添加如下

export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=$JAVA_HOME/bin:$PATH
export CLASS_PATH=$JAVA_HOME/lib

编辑后保存, 执行 source ~/.bash_profile生效。

java -version 检查
mac系统 mvn打包报错:No compiler is provided in this environment. Perhaps you are running on a JRE插图2

2.3 查看mvn 版本

执行 mvn -version 查看

Java version 正确,但是 runtime 值为 /Library/Internet Plug-Ins/JavaAppletPlugin.plugin

进入 /Library/Internet Plug-Ins/ 目录,删除 /Library/Internet Plug-Ins/JavaAppletPlugin.plugin

重新执行 mvn -version runtime 正确,如下图所示(装了JDK9,JDK8也类似)。
mac系统 mvn打包报错:No compiler is provided in this environment. Perhaps you are running on a JRE插图3

再回到项目中执行 mvn 编译命令等,恢复正常。

三、感悟

可能是性格问题,或许有些缺乏延迟满足,总是想追求最新的软件和电子产品。
新的东西固然好,但是很容易成为小白鼠,成为第一批趟坑的人。

原文链接:https://blog.csdn.net/w605283073/article/details/111770386

本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。

未经允许不得转载:起风网 » mac系统 mvn打包报错:No compiler is provided in this environment. Perhaps you are running on a JRE
分享到: 生成海报

评论 抢沙发

评论前必须登录!

立即登录