【问题标题】:Maven build does not compileMaven 构建无法编译
【发布时间】:2017-12-03 07:58:42
【问题描述】:

我正在尝试编译一个 maven 项目,但出现以下错误:

[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java (default-cli) on project storm-example: The parameters 'mainClass' for goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java are missing or invalid -> [Help 1]

我实际上是 Maven 项目的新手。问题是我根本没有使用 codehous.mojo 插件。从我从不同的现有问题中看到,得到这个的人在构建中使用 mojo 插件,但在我的情况下,我只需要 maven-assembly-plugin。尽管没有明确需要,我是否在每个 maven 对象中都需要 mojo?

以下是我的maven 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.learningstorm</groupId>
  <artifactId>storm-example</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>storm-example</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

<dependencies>
  <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.11</version>
    <scope>test</scope>
  </dependency>

  <dependency>
    <groupId>org.apache.storm</groupId>
    <artifactId>storm-core</artifactId>
    <version>1.0.0</version>
    <scope>provided</scope>
  </dependency>
</dependencies>

<repositories>
  <repository>
    <id>clojars.org</id>
    <url>http://clojars.org/repo</url>
  </repository>
</repositories>


<build>
  <plugins>
    <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <version>3.0.0</version>
      <configuration>
        <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
        <archive>
          <manifest>
            <mainClass />
          </manifest>
        </archive>
      </configuration>
      <executions>
        <execution>
          <id>make-assembly</id>
          <phase>package</phase>
          <goals>
            <goal>single</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

</project>

【问题讨论】:

    标签: java maven maven-plugin maven-assembly-plugin


    【解决方案1】:

    该错误是对您在 maven-assembly-plugin 配置中的以下标签的抱怨:

    <archive>
      <manifest>
        <mainClass />
      </manifest>
    </archive>
    

    除非你想创建一个可执行的jar(在这种情况下你应该指定“main”类的限定名),你应该删除整个&lt;archive&gt;标签。

    您的工作似乎围绕“创建可执行 JAR” maven-assembly-plugin's usage page 的示例,而您可能只需要第一个基本示例中定义的内容。

    【讨论】:

    • 我试着把它拿出来,但还是不行。相同的错误信息。我使用mvn compile exec:java -Dexec.classpathScope=compile 编译它。相同的错误信息。你能告诉我如何在代码中加入这种依赖关系吗?
    • @Mnemosyne 你确定这是完全相同的错误信息吗?因为这个非常明确。你到底想打包什么?图书馆?
    • @Mnemosyne 你可能有一个错误,因为&lt;descriptorRef&gt;jar-with-dependencies&lt;/descriptorRef&gt; 现在我猜。您不应该只是从使用页面复制示例,还应该阅读它们的含义
    猜你喜欢
    • 2019-04-01
    • 1970-01-01
    • 2019-02-24
    • 2014-12-20
    • 1970-01-01
    • 2020-12-04
    • 2015-03-14
    • 2021-02-07
    • 1970-01-01
    相关资源
    最近更新 更多