使用maven编译时无法找到Javac编译器 - 无法在以下位置找到Javac编译器:

时间:2012-11-01 11:07:02

标签: eclipse maven compiler-errors

编译maven时出现编译错误。

[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] Unable to locate the Javac Compiler in:
  C:\Program Files\Java\jre1.6.0_05\..\lib\tools.jar

所以我设置JAVA_HOME环境变量但没有优势。错误似乎路径中的 maven搜索java编译器,而不是JAVA_HOME

  • JAVA_HOMEC:\Program Files\Java\jdk1.6.0_05

  • 已安装的JRE为C:\Program Files\Java\jre1.6.0_05

  • 我的PATH变量是:

  

C:\Program Files\PC Connectivity Solution\;D:\alfrescoplatform\ImageMagick;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32\Wbem;C:\Program Files\ImageMagick-6.7.3-Q16;C:\Program Files\Java\jdk1.6.0_05\bin

这是我的详细日志

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building SpringMVC Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ SpringMVC ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ SpringMVC ---
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 2 source files to D:\Learning\spring-workspace\SpringMVC2.5.6\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] Unable to locate the Javac Compiler in:
  C:\Program Files\Java\jre1.6.0_05\..\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: 2.719s
[INFO] Finished at: Thu Nov 01 17:22:43 MMT 2012
[INFO] Final Memory: 4M/8M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project SpringMVC: Compilation failure
[ERROR] Unable to locate the Javac Compiler in:
[ERROR] C:\Program Files\Java\jre1.6.0_05\..\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

如果您对此有任何疑问,请与我联系。

3 个答案:

答案 0 :(得分:1)

您的JAVA_HOME是C:\ Program Files \ Java \ jdk1.6.0_05

方式1 :以下步骤适用于Eclipse:

  1. 转到窗口 - >偏好 - > Java - >安装了JREs
  2. 将现有JRE位置编辑为:设置JRE Home = JAVA_HOME或JAVA_HOME \ jre(在您的情况下,路径应为C:\ Program Files \ Java \ jdk1.6.0_05或C:\ Program Files \ Java \ jdk1。 6.0_05 \ JRE)
  3. 单击“完成”和“确定”按钮
  4. 方式2 :设置JRE系统库的另一种方法:

    1. 打开eclipse并右键单击Eclipse项目属性
    2. Java构建路径 - >库
    3. 选择JRE系统库 - >单击编辑按钮
    4. 点击"已安装的JRE ..."按钮
    5. 将JRE编辑为:设置JRE Home = JAVA_HOME或JAVA_HOME \ jre
    6. 方式3 :以下步骤也应运行良好:

      1. 转到窗口 - >偏好 - > Java - >已安装JRE
      2. 选择您正在使用的JRE
      3. 按编辑 - >添加外部JAR ......
      4. 浏览到Java \ jdk1.6.0_05 \ lib并选择tools.jar并按Enter键
      5. 单击“完成”和“确定”按钮

答案 1 :(得分:0)

尝试将vm参数添加到eclipse.ini文件中。

-vm
C:\Program Files\Java\jdk1.6.0_05\bin\javaw.exe

答案 2 :(得分:0)

我遇到了同样的问题,尝试了这些解决方案却没有成功:


什么对我有用:

  • 点击绿色运行按钮click
  • 旁边的小向下箭头
  • 选择运行配置
  • JRE 标签上,选择备用JRE ,然后选择您想要的目标(如果它不在列表中,请单击已安装的JRE < / em>将其添加进去。)