问题描述
我在屏幕截图上看到了这个错误,我也看到了其他关于它的帖子,但是,提供的修复主要是针对 Windows 的,所以我尝试的任何方法都没有解决我的 Mac 上的问题.
目前,当我运行/usr/libexec/java_home 时,它指向我这里:/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
所以当运行一个 Maven 项目时,它会通过这样的消息:此环境中不提供编译器.也许您在 JRE 而不是 JDK 上运行?
所以,我想知道 JAVA_HOME 的位置是否不正确,如果是,我该如何解决?对不起,如果问一些明显的问题,但我是新手.
非常感谢您的帮助.
我遇到了和你一样的问题.
此解决方案 (构建失败运行 "mvn clean安装".我刚刚升级了 Big Sur) 是为了删除无用的 jre.
我的是给 mvn shell 一个正确的 java_home.
解决方案 - 编辑 mvn bash
步骤 1:检查如何通过 /usr/libexec/java_home
过滤目标 java当我运行命令 /usr/libexec/java_home -V
我可以看到 2 个虚拟机
MacBook-Pro:bin charles$/usr/libexec/java_home -V匹配Java虚拟机(二):1.8.251.08 (x86_64) 甲骨文公司"- Java"/库/互联网插件/JavaAppletPlugin.plugin/Contents/Home1.8.0_251 (x86_64) 甲骨文公司"- Java SE 8"/库/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home/库/互联网插件/JavaAppletPlugin.plugin/Contents/Home
我的/usr/libexec/java_home
默认返回值是我的jre路径比如
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
但是我可以改变返回jdk路径
/Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home
如果我运行命令/usr/libexec/java_home -v1.8.0
第 2 步:更新 mvn shell
在 mvn shell 中找到以下几行
if [ -z "$JAVA_HOME";] &&[ -x "/usr/libexec/java_home";];然后## 苹果 JDK#导出 JAVA_HOME=`/usr/libexec/java_home`菲因为我可以使用 usr/libexec/java_home -v1.8.0
来确保系统使用 jdk,我将我的外壳更新为
if [ -z "$JAVA_HOME";] &&[ -x "/usr/libexec/java_home";];然后## 苹果 JDK#导出 JAVA_HOME=`/usr/libexec/java_home -v1.8.0`菲
然后,它起作用了.
如何查看差异
mvn -version
在我更新我的 mvn 之前,我会看到
MacBook-Pro:~ charles$ mvn -version阿帕奇 Maven ........Maven家:........Java 版本:1.8.0_251,供应商:Oracle CorporationJava 主页:/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home默认语言环境:zh_TW,平台编码:UTF-8操作系统名称:mac os x",版本:10.16",架构:x86_64",系列:mac"
更新我的 mvn 后,我可以看到结果
MacBook-Pro:~ charles$ mvn -version阿帕奇 Maven ........马文家:......Java 版本:1.8.0_251,供应商:Oracle CorporationJava 主页:/Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home/jre默认语言环境:zh_TW,平台编码:UTF-8操作系统名称:mac os x",版本:10.16",架构:x86_64",系列:mac"
虽然java home显示为jre路径,但是jre是jdk里面的子文件夹.没关系.
I am getting this error on the screenshot and I have seen other posts about it, however, the fixes provided are mainly for Windows, so whatever I tried did not fix the issue on my Mac.
Currently, when I run /usr/libexec/java_home it points me here:/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
So when running a maven project it throughs message like this:No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
So, I am wondering if the location of JAVA_HOME is incorrect, and if so how can I fix it?Sorry, if asking something obvious questions, but I am new to this.
I would really appreciate your help.
I meet the same question as yours.
This solution (Build failure run "mvn clean install". I just upgraded Big Sur) is to remove useless jre.
Mine is to give mvn shell a correct java_home.
Solution - edit mvn bash
Step 1: Check how to filter your target java by /usr/libexec/java_home
When I run command /usr/libexec/java_home -V
I can see 2 virtual machines
MacBook-Pro:bin charles$ /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
1.8.251.08 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
1.8.0_251 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
My default return value of /usr/libexec/java_home
is my jre path such as
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
But I can change the return jdk path
/Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home
if I run command/usr/libexec/java_home -v1.8.0
Step 2: Update mvn shell
Find following lines in mvn shell
if [ -z "$JAVA_HOME" ] && [ -x "/usr/libexec/java_home" ]; then
#
# Apple JDKs
#
export JAVA_HOME=`/usr/libexec/java_home`
fi
Because I can use usr/libexec/java_home -v1.8.0
to make sure system using jdk,I update my shell as
if [ -z "$JAVA_HOME" ] && [ -x "/usr/libexec/java_home" ]; then
#
# Apple JDKs
#
export JAVA_HOME=`/usr/libexec/java_home -v1.8.0`
fi
And then, it works.
How to check difference
mvn -version
Before I update my mvn, I will see
MacBook-Pro:~ charles$ mvn -version
Apache Maven ........
Maven home: ........
Java version: 1.8.0_251, vendor: Oracle Corporation
Java home: /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
Default locale: zh_TW, platform encoding: UTF-8
OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"
After I update my mvn, I can see the result
MacBook-Pro:~ charles$ mvn -version
Apache Maven ........
Maven home: .......
Java version: 1.8.0_251, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home/jre
Default locale: zh_TW, platform encoding: UTF-8
OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"
Though java home display as jre path, but the jre is sub-folder inside of jdk. It's ok.
这篇关于Mac os 大苏尔 |此环境中不提供编译器.也许您在 JRE 而不是 JDK 上运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!