生成失败运行“mvn 全新安装”。我刚刚升级了大苏尔

2022-09-03 08:24:58

mvn 全新安装建筑物故障

  [INFO] Total time:  1.911 s
    [INFO] Finished at: 2020-11-14T19:07:37+08:00
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project es-starter: Compilation failure
    [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
    [ERROR]
    [ERROR] -> [Help 1]
    [ERROR]
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR]
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

Java & Maven 环境

➜

      ~ which java
    /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java
    ➜  ~ mvn -v
    Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-05T03:00:29+08:00)
    Maven home: /Users/munan/Documents/work/develop/maven/apache-maven-3.6.1
    Java version: 1.8.0_192, vendor: Oracle Corporation, runtime: /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"

环境似乎没有问题。那么导致构建失败的问题在哪里呢?


答案 1

BigSur出于某种原因添加了JRE路径,我卸载了JRE,因为我需要JDK(而不是JRE),它起作用了。

  1. 转到/库/互联网插件。
  2. 通过以 root 用户身份执行 rm 命令或使用 sudo 工具,删除 JavaAppletPlugin.plugin目录。
  3. 转到/库/首选项窗格。
  4. 通过以 root 用户身份执行 rm 命令或使用 sudo 工具来删除 JavaControlPanel.prefpane。

答案 2

将Mac更新到Big Sur后,我遇到了同样的问题!

BigSur出于某种原因添加了JRE路径,并且优先级高于自己JDK。

这是我的解决方案:

第一:

/usr/libexec/java_home -V

那么也许你会得到:

Matching Java Virtual Machines (2):
    1.8.202.08 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
    1.8.0_202 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home

所以第二个是我们真正的JDK。只需在bash配置文件中编辑JAVA_HOME即可。

vim ~/.zshrc
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home"
source vim ~/.zshrc
echo $JAVA_HOME

然后它就会起作用!享受Bug Sur!

或者你可以通过这个 cmd 重新安装 jdk8:

brew tap adoptopenjdk/openjdk
brew cask install adoptopenjdk8

推荐