5

使用 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了环境变量但没有优势。该错误似乎是在 jre 路径中搜索 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

如果您对此有任何想法,请告诉我。

4

3 回答 3

1

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

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

  1. 转到窗口 -> 首选项 -> Java -> 已安装的 JRE
  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. 单击完成和确定按钮

方式2:另一种设置JRE系统库的方式:

  1. 打开 Eclipse 并右键单击 Eclipse 项目属性
  2. Java 构建路径 -> 库
  3. 选择 JRE 系统库 -> 单击编辑按钮
  4. 单击“已安装的 JRE...”按钮
  5. 将 JRE 编辑为:设置 JRE Home = JAVA_HOME 或 JAVA_HOME\jre

方式3:以下步骤也应该很好用:

  1. 转到窗口 -> 首选项 -> Java -> 已安装的 JRE
  2. 选择您正在使用的 JRE
  3. 按编辑-> 添加外部 JAR...
  4. 浏览到 Java\jdk1.6.0_05\lib 并选择 tools.jar 并按 Enter
  5. 单击完成和确定按钮
于 2015-04-29T12:04:27.913 回答
0

尝试向您的文件添加vm参数。eclipse.ini

-vm
C:\Program Files\Java\jdk1.6.0_05\bin\javaw.exe
于 2012-11-01T11:48:45.450 回答
0

我有完全相同的问题,尝试了这些解决方案但没有成功:


什么对我有用:

  • 单击绿色运行按钮旁边的小向下箭头点击
  • 选择运行配置
  • JRE选项卡上,选择Alternate JRE,然后选择所需的目标(如果它不在列表中,请单击Installed JREs将其添加)。
于 2015-02-05T22:15:53.687 回答