使用Idea 一直正常,今天maven打包时出现这个问题Unable to locate the Javac Compiler in
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project xxxxx-api: Compilation failure
[ERROR] Unable to locate the Javac Compiler in:
[ERROR] /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/../lib/tools.jar
[ERROR] Please ensure you are using JDK 1.4 or above and
[ERROR] not a JRE (the com.sun.tools.javac.Main class is required).
[ERROR] In most cases you can change the location of your Java
[ERROR] installation by setting the JAVA_HOME environment variable.
原因是不知道啥时候装了多个版本jdk,idea获取Java-home出现了不一致,卸载留一个就行
我的是MacBook Pro,解决步骤:
1.执行命令 /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
1.8.181.13 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
1.8.0_181 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
有两个版本
2.sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
删除此版本
3.执行 /usr/libexec/java_home -V 只有下面一个jdk
Matching Java Virtual Machines (1):
1.8.0_181 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home
java -version 也正常输出
mvn package / mvn deploy 可以正常打包/正常deploy