2013-06-06 270 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”