执行 mvn clean compile
报错:
[ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? [INFO] 1 error [INFO] ------------------------------------------------------------- [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 4.144 s [INFO] Finished at: 2022-07-25T19:01:28+08:00 [INFO] Final Memory: 39M/437M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project cctv-client: 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]
修复方法
1.查看java_home
MacBook-Pro-2:bin tianyue$ /usr/libexec/java_home
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
MacBook-Pro-2:bin tianyue$ pwd
/Users/tianyue/data/maven/apache-maven-3.5.0/bin
2.看环境变量
MacBook-Pro-2:bin bao$ cat ~/.bash_profile
export M2_HOME=/Users/bao/data/maven/apache-maven-3.5.0
export PATH=$PATH:$M2_HOME/bin
PATH=$PATH:/usr/local/mysql/bin
3.修改环境变量
先使用/usr/libexec/java_home -V查找想要的JDK地址后,修改~/.bash_profile
MacBook-Pro-2:bin bao$ cat ~/.bash_profile export M2_HOME=/Users/bao/data/maven/apache-maven-3.5.0 export PATH=$PATH:$M2_HOME/bin PATH=$PATH:/usr/local/mysql/bin JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home export JAVA_HOME
修改后执行source ~/.bash_profile
在新窗口打开
MacBook-Pro-2:bin bao$ /usr/libexec/java_home -V
Matching Java Virtual Machines (3):
1.8.131.11 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
1.8.0_131 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
1.7.0_80 (x86_64) "Oracle Corporation" - "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
MacBook-Pro-2:developer-client bao$ mvn -version Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-04T03:39:06+08:00) Maven home: /Users/bao/data/maven/apache-maven-3.5.0 Java version: 1.8.0_131, vendor: Oracle Corporation Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre Default locale: en_US, platform encoding: UTF-8 OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"
mvn clean comiple 成功



