maven - 执行 javac : Compilation failure 失败

标签 maven

在两台不同的笔记本电脑上使用 maven 构建同一项目。一方面它运行良好,一方面它显示错误。

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

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 clean install -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 文件夹。

最佳答案

我遇到了这个问题,并通过一些故障排除解决了它。

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

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

Maven 正在尝试执行 javac 来编译您的代码,但没有正确的路径。对于许多设置,您需要检查 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>

关于maven - 执行 javac : Compilation failure 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16956514/

相关文章:

java - 如何通过maven连接吗啡注释类?

java - Google Analytics 中的 Invalid_grant

maven - 从 XJC 中导入的模式解析类型定义失败

maven - 在 Apache karaf 上的 bundle 中使用 Apache Camel

java - 如何创建一个空的多模块 Maven 项目?

Maven 错误 : package javax. servlet 不存在

java - Tomcat 6 下的 JSF 2.0 应用程序 : "No Factories configured."

java - 使用 Maven 构建应用程序失败,我可以在本地运行代码,但无法在 heroku 上部署

spring - 显示使用 Tomcat7 Maven 插件但未使用独立 Tomcat 的主页

java - Maven - 在 Quickstart Archetype 中更改 jUnit 版本