2012-11-01 201 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. 單擊「完成」並單擊「確定」按鈕
相關問題