maven:打包异常 Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (defa
最近maven打包项目时出现以下异常:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project bo-server-api: Compilation failure [ERROR] Unable to locate the Javac Compiler in: [ERROR] D:\Aimsen\myDevelopKit\1.software\jdk\64位\1.8\jdk-8-windows-x64\..\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. |
原因:项目打包使用了以下插件,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>1.8</source><!-- 源代码使用的JDK版本 --> <target>1.8</target><!-- 需要生成的目标class文件的编译版本 --> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> |