简体   繁体   English

无法执行目标org.apache.maven.plugins:maven-compiler-plugin

[英]Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin

I'm trying compile using mvn install but I'm getting this error: 我正在尝试使用mvn install编译,但我收到此错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project test: Compilation failure: Compilation failure: [错误]无法执行目标org.apache.maven.plugins:maven-compiler-plugin:2.0.2:项目测试时编译(default-compile):编译失败:编译失败:

pom.xml file: 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>

How to fix it? 怎么解决?

Your issue is most likely the <scope> of the dependency. 您的问题很可能是依赖项的<scope> When inside of the IDE, all scopes are added to the build path of the project. 在IDE内部时,所有范围都将添加到项目的构建路径中。 However, when running mvn only the appropriate scopes are added to the classpath for the javac command. 但是,在运行mvn只会将适当的作用域添加到javac命令的类路径中。 For example, if you had a class in /src/main/java that imported a class from one of your dependencies scoped to <scope>test</scope> , the IDE would be able to build the project, but mvn would fail in the manner you are experiencing. 例如,如果/src/main/java中有一个类从一个作用<scope>test</scope>导入一个类,该类依赖于<scope>test</scope> ,那么IDE将能够构建项目,但是mvn会失败你正在经历的方式。

I encountered a similar error when trying to download and compile the aws kinesis consumer library (kcl) 尝试下载和编译aws kinesis使用者库(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

It turns out that while I had updated my version of Java from 1.6 to 1.7, I had not updated Javac from 1.6 to 1.7. 事实证明,虽然我将我的Java版本从1.6更新为1.7,但我没有将Javac从1.6更新为1.7。

To do so I used the following command on ubuntu 为此,我在ubuntu上使用了以下命令

sudo update-alternatives --config javac

And then choose the desired version at the prompt. 然后在提示符下选择所需的版本。

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:

I hope this helps someone else. 我希望这有助于其他人。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Maven:未能执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.10.1compile: - Maven: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile 无法执行目标org.apache.maven.plugins:maven-compiler-plugin等 - Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin AND more Intelij IDEA-无法执行目标org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile - Intelij IDEA - Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile 无法执行目标org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile - Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile 无法执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.8.1:testCompile - Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:testCompile 未能执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.8.1 - Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1 无法执行目标org.apache.maven.plugins:maven-compiler-plugin:3.1:compile - Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile tools.jar问题无法执行目标org.apache.maven.plugins:maven-compiler-plugin - tools.jar issue Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin 未能执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile - Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1 - org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM