执行目标org.apache.maven.plugins:maven-compiler-plugin失败



我正在尝试使用mvn install编译,但我得到这个错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project test:编译失败:编译失败:

pom.xml文件:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany</groupId>
  <artifactId>test</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>test</name>
  <url>http://maven.apache.org</url>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
<build>
  <plugins>
    <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <configuration>
        <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
        <archive>
          <manifest>
            <mainClass>com.mycompany.test.App</mainClass>
          </manifest>
        </archive>
      </configuration>
    </plugin>
  </plugins>
</build>
  <dependencies>
    <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.25</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

如何修复?

您的问题很可能是依赖项的<scope>。在IDE中,所有作用域都被添加到项目的构建路径中。但是,当运行mvn时,javac命令的类路径中只会添加相应的作用域。例如,如果您在/src/main/java中有一个类,该类从您的依赖项之一导入到<scope>test</scope>, IDE将能够构建项目,但mvn将以您正在经历的方式失败。

我在尝试下载和编译aws kineesis消费者库(kcl)时遇到了类似的错误

[INFO] --- maven-compiler-plugin:2.0.2:compile (default-compile) @ amazon-kinesis-client ---
[INFO] Compiling 81 source files to /opt/speedshiftmedia/aws.kcl/1.1.0/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.822s
[INFO] Finished at: Tue Jul 22 12:31:39 PDT 2014
[INFO] Final Memory: 4M/56M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project amazon-kinesis-client: Compilation failure
[ERROR] Failure executing javac, but could not parse the error:
[ERROR] javac: invalid target release: 1.7

结果是,当我将Java版本从1.6更新到1.7时,我没有将Javac从1.6更新到1.7。

为了做到这一点,我在ubuntu 上使用了以下命令
sudo update-alternatives --config javac

然后在提示符下选择所需的版本。

There are 2 choices for the alternative javac (providing /usr/bin/javac).

Selection    Path                                         Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-6-openjdk-amd64/bin/javac   1061      auto mode
   1            /usr/lib/jvm/java-6-openjdk-amd64/bin/javac   1061      manual mode
   2            /usr/lib/jvm/java-7-openjdk-amd64/bin/javac   1051      manual mode
Press enter to keep the current choice[*], or type selection number:

我希望这能帮助到别人。

相关内容

  • 没有找到相关文章

最新更新