最近maven打包项目时出现以下异常:
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project com.xxx: Compilation failure
Unable to locate the Javac Compiler in:
E:\JDK1.8\jdk_1.8.0_20\..\lib\tools.jar
Please ensure you are using JDK 1.4 or above and not a JRE (the com.sun.tools.javac.Main class is required).
In most cases you can change the location of your Java installation by setting the JAVA_HOME environment variable.
原因:项目打包使用了以下插件,maven打包时会根据生命周期运行插件,以下插件在编译时运行,不设置版本时默认为2.3.2,由于个人的Java版本为1.8的,而该插件版本2.3.2太旧所以不支持1.8,直接到http://search.maven.org搜maven-compiler-plugin把copy最新版本即可解决问题(当然也不一定需要最新的)。
当然也不排除其它原因(如环境变量,但这种情况比较小),这只是个人遇到的问题解决方法
<plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.6.1</version> <configuration> <source>${java.version}</source> <target>${java.version}</target> <encoding>UTF-8</encoding> </configuration> </plugin>