maven报错:Unable to locate the Javac Compiler in: D:\Program Files\Java\jre7\..\lib\tools.jar

现象:maven项目之间mvn install报如下错误:

Unable to locate the Javac Compiler in: D:\Program Files\Java\jre7\..\lib\tools.jar
[ERROR] Unable to locate the Javac Compiler in:
  D:\Program Files\Java\jre7\..\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

检查下eclipse环境jre配置:

maven报错:Unable to locate the Javac Compiler in: D:\Program Files\Java\jre7\..\lib\tools.jar

根据报错信息提示:maven要求jre使用自己本地安装的jdk下的jre故这样修改:

windows--perference--java--installed jres下设置jre为本地安装的jdk下jre如下截图所示:

maven报错:Unable to locate the Javac Compiler in: D:\Program Files\Java\jre7\..\lib\tools.jar


配置好后重新启动eclipse(若不重新启动,可能会存在修改不成功)

然后重新对maven执行命令mvn installl,maven能够正常编译。