2012-11-01 160 views
5

编译maven时出现编译错误。使用maven编译时无法找到Javac编译器 - 无法找到Javac编译器:

[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编译器在JRE路径中,而不是在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 

如果您对此有任何的想法,让我知道。

+0

可以包含'mvn --version'的输出吗? –

+0

(你确实在设置'JAVA_HOME'后启动了一个* new *命令窗口,对吗?) –

+0

我只是在eclipse中使用maven plugin。 – swemon

回答

0

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

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

您的JAVA_HOME是C:\ Program Files \ Java \ jdk1.6。0_05

路1:以下步骤将Eclipse的工作:

  1. 去窗口 - >首选项 - >爪哇 - >安装的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. 点击Finish确定按钮

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

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

路3:下面的步骤也应该很好地工作:

  1. 去窗口 - >首选项 - >爪哇 - >安装的JRE
  2. 选择JRE使用的是
  3. 出版社编辑 - >添加外部JAR ...
  4. 浏览到Java \ jdk1.6.0_05 \ lib和选择的tools.jar和按Enter键
  5. 单击“完成”并单击“确定”按钮
相关问题