2013-06-06 153 views
5

相同的項目在兩臺不同的筆記本電腦上使用maven構建。在一個運行良好和一個顯示錯誤。執行javac失敗:編譯失敗

狀態:兩個系統的配置相同。使用

C:\Users\admin>mvn -version 
Apache Maven 2.2.1 (r801777; 2009-08-07 00:46:01+0530) 
Java version: 1.6.0_43 
Java home: C:\Installers\Java\jdk1.6.0_43\jre 
Default locale: en_IN, platform encoding: Cp1252 
OS name: "windows 7" version: "6.1" arch: "amd64" Family: "windows" 

命令:MVN全新安裝-DskipTests =真

錯誤:

[INFO] [compiler:compile {execution: default-compile}] 
[INFO] Compiling 3 source files to C:\Users\admin\HeliosWorkspace\...\target\classes 
[INFO] ------------------------------------------------------------------------ 
[ERROR] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Compilation failure 
Failure executing javac, but could not parse the error: 
The system cannot find the path specified. 

[INFO] ------------------------------------------------------------------------ 
[INFO] Trace 
org.apache.maven.BuildFailureException: Compilation failure 
Failure executing javac, but could not parse the error: 
The system cannot find the path specified.  

     at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor 
.java:715) 
     at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifec 
ycleExecutor.java:556) 
     at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor. 
java:535) 
     at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultL 
ifecycleExecutor.java:387) 
     at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleE 
xecutor.java:348) 
     at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java 
:180) 
     at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328) 
     at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138) 
     at org.apache.maven.cli.MavenCli.main(MavenCli.java:362) 
     at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315) 
     at org.codehaus.classworlds.Launcher.launch(Launcher.java:255) 
     at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430) 
     at org.codehaus.classworlds.Launcher.main(Launcher.java:375) 
Caused by: org.apache.maven.plugin.CompilationFailureException: Compilation failure 
Failure executing javac, but could not parse the error: 
The system cannot find the path specified. 

我甚至嘗試甚至刪除一切都像重新創建文件夾的.m2。

+0

執行'mvn -X clean install -DskipTests = true'來查看調試輸出並將其粘貼到此處。 –

+0

檢查你的Java_Home變量 – Adarsh

+0

同時檢查編譯器插件是否配置正確。 –

回答

1

感謝所有,現在它的工作:

mvn -X clean install -DskipTests=true 

調試模式是非常有益的。

0

檢查您的POM文件,並確保您有MVN和Java合適的環境變量

0

我也有類似的問題,我發現的settings.xml @ MAVEN_HOME/conf目錄或C:\用戶\ .m2目錄\ settings.xml指向一個錯誤的JDK路徑,糾正了哪個修復了這個問題。上面打印的錯誤消息實際上是指出「執行失敗的javac」,這意味着Maven沒有找到JDK。

感謝 Hithesh

3

我有這個問題,並與一些故障排除解決它。

當您嘗試執行文件但輸入無效路徑時,實際上是DOS錯誤消息。

C:\Users\me>c:\asdf\foo.exe 
The system cannot find the path specified. 

Maven是試圖執行的javac編譯代碼,但沒有正確的path.For很多設置,你將需要檢查的路徑,你的編譯器在你的pom.xml。轉到cmd提示符並複製並粘貼,並確保其有效路徑。

對於使用settings.xml配置文件在不同JAVA_HOME上定義一些全局配置的設置(例如以下示例),請確保每個變量中的路徑都正確,包含這些變量的配置文件處於活動狀態(activeProfile標記可以確保這一點) ,並且正確地在你的pom.xml引用

<!-- settings.xml --> 
<profiles> 
<profile> 
    <id>compiler-versions</id> 
    <properties> 
     <JAVA_1_5_HOME>C:/java/jdk1.5.0_16</JAVA_1_5_HOME> 
     <JAVA_1_6_HOME>C:/java/jdk1.6.0_43</JAVA_1_6_HOME> 
     <JAVA_1_7_HOME>C:/java/jdk1.7.0_55</JAVA_1_7_HOME> 
    </properties> 
</profile> 
</profiles> 


<activeProfiles> 
    <!-- make the profile active all the time --> 
    <activeProfile>compiler-versions</activeProfile> 
</activeProfiles> 

的pom.xml片段:

<!-- pom.xml --> 
<!-- ... --> 
<build> 
      <configuration> 
       <verbose>false</verbose> 
       <fork>true</fork> 
       <executable>${JAVA_1_6_HOME}/bin/javac</executable> 
       <compilerVersion>1.6</compilerVersion> 
       <meminitial>256m</meminitial> 
       <source>1.6</source> 
       <target>1.6</target> 
       <!--encoding>UTF-8</encoding--> 
       <maxmem>512m</maxmem> 
      </configuration> 
</build> 
0

我知道這是一個老話題,但我認爲這個答案將幫助人們在未來:

Java home: C:\Installers\Java\jdk1.6.0_43\jre

您正在使用JRE而不是JDK。只需從您的java主頁中刪除「\ jre」