执行Javac失败:编译失败 [英] Failure executing javac: Compilation failure

查看:90
本文介绍了执行Javac失败:编译失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

同一项目在两台不同的笔记本电脑上使用maven进行构建.一种是运行良好,另一种是显示错误.

Same project Building using maven on two different laptops. On one its running good and on one its showing error.

状态:两个系统的配置都相同.

Status: Both Systems are of same configurations.

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 = true

错误:

[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文件夹.

I even tried even deleting everything like creating .m2 folder again.

推荐答案

我遇到了此问题,并通过一些故障排除解决了该问题.

I had this issue, and resolved it with some troubleshooting.

当您尝试执行文件但输入无效路径时,这实际上是DOS错误消息.

This is actually a DOS error message when you try to execute a file but enter an invalid path to it.

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

Maven试图执行javac来编译代码,但是没有正确的路径.对于许多设置,您需要在pom.xml中检查编译器的路径.转到cmd提示符,然后将其复制并粘贴到其中,并确保其有效路径.

Maven is trying to execute javac to compile your code but doesn't have the correct path.For many setups, you will need to check the path to your compiler in your pom.xml. Go to the cmd prompt and copy and paste it in and make sure its a valid path.

对于使用settings.xml配置文件在不同JAVA_HOME上定义一些全局配置的安装程序(例如以下示例),请确保每个变量中的路径均正确,具有这些变量的配置文件处于活动状态(activeProfile标记可以确保实现此目的),并在您的pom.xml中正确引用了

For a setup that uses settings.xml profiles to define some global configurations on different JAVA_HOMEs such as the below example, ensure the paths are correct in each variable, the profile with these variables is active (activeProfile tags can ensure this), and is correctly referenced in your 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 snippet:

<!-- 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>

这篇关于执行Javac失败:编译失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆