您的位置:首页 > 编程语言 > Java开发

Maven报错: Unable to locate the Javac Compiler in: D:\Program\java\jre1.7.0_45\..\lib\tools.jar

2016-03-09 12:57 579 查看
使用Eclipse Mars 新建Maven项目,出现以下错误:

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building maven_hello 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ maven_hello ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory F:\workspace\workspace_mars\maven_hello\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ maven_hello ---
[INFO] Compiling 2 source files to F:\workspace\workspace_mars\maven_hello\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] Unable to locate the Javac Compiler in:
D:\Program\java\jre1.7.0_45\..\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.
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.888s
[INFO] Finished at: Wed Mar 09 11:56:53 CST 2016
[INFO] Final Memory: 6M/122M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project maven_hello: Compilation failure
[ERROR] Unable to locate the Javac Compiler in:
[ERROR] D:\Program\java\jre1.7.0_45\..\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.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

注意:主要错误信息在这里, 

Unable to locate the Javac Compiler in:
D:\Program\java\jre1.7.0_45\..\lib\tools.jar


 没有在以上路径中找到 toor.jar , 我查看自己的安装路径发现,jre1.7.0_45的外层目录中没有lib 文件夹,也就无法找到toor.jar包。原来当初安装JDK和JRE的时候,JRE单独安装在了外面。在JRE同一级目录中并没有JDK的lib包。所以找不到toor.jar 



然后,在Eclipse中重新配置JRE如下:

修改为这个JRE后,同一级目录下能够lib 包下的toor.jar。 然后再次用Maven编译,通过!

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  maven eclipse