【问题标题】:m2e shade eclipse "project main artifact does not exist"m2e shade eclipse“项目主工件不存在”
【发布时间】:2013-01-07 19:39:57
【问题描述】:

我正在尝试制作一个部署包,它将我的 maven 模块的所有依赖项捆绑在一起,该模块依赖于 eclipse 中的另一个 maven 项目。

我的 pom.xml 中有这个

<modelVersion>4.0.0</modelVersion>
<groupId>com.my.proj</groupId>
<artifactId>AAA</artifactId>
<version>0.0.2-SNAPSHOT</version>
<name>btc</name>
<dependencies>
    <dependency>
        <groupId>com.another.proj</groupId>
        <artifactId>BBB</artifactId>
        <version>1.4-SNAPSHOT</version>
    </dependency>
</dependencies>

<build>
    <plugins>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>1.6</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>com.group.id.Launcher1</mainClass>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>

    </plugins>
</build>

我在 Eclipse 中使用“m2 Maven Build”,目标是“org.apache.maven.plugins:maven-shade-plugin:shade”并勾选“解决工作区工件”。

失败了

--- maven-shade-plugin:1.6:shade (default-cli) @ AAA ---
[ERROR] The project main artifact does not exist. This could have the following
[ERROR] reasons:
[ERROR] - You have invoked the goal directly from the command line. This is not
[ERROR]   supported. Please add the goal to the default lifecycle via an
[ERROR]   <execution> element in your POM and use "mvn package" to have it run.
[ERROR] - You have bound the goal to a lifecycle phase before "package". Please
[ERROR]   remove this binding from your POM such that the goal will be run in
[ERROR]   the proper phase.

此时我已经没有想法了。

【问题讨论】:

    标签: eclipse maven-2 m2e maven-shade-plugin


    【解决方案1】:

    [错误] 项目主工件不存在。这可能有以下内容

    我们最近遇到了这个问题。为我们解决的问题是执行mvn shade:shade,而是使用:

    mvn package
    

    这会在运行 shade 插件之前进行额外的编译和打包工作,因此主类在类路径中可用。

    【讨论】:

      【解决方案2】:

      shade 插件正在尝试将项目的工件包含在 shaded JAR 中。由于它(尚)不存在,因此您会收到此错误。您需要先构建/打包项目工件(例如,通过将阴影目标附加到打包阶段)

      如果您没有任何项目工件要包含在阴影 JAR 中,您可以添加一个 excludes 节点来删除项目的工件。

      这是一个例子:

      <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-shade-plugin</artifactId>
              <version>1.6</version>
              <executions>
                  <execution>
                      <phase>package</phase>
                      <goals>
                          <goal>shade</goal>
                      </goals>
                      <configuration>
                          <transformers>
                              <transformer
                                  implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                  <mainClass>com.group.id.Launcher1</mainClass>
                              </transformer>
                          </transformers>
                          <excludes>
                              <exclude>com.my.proj:AAA</exclude>
                          </excludes>
                      </configuration>
                  </execution>
              </executions>
          </plugin>
      

      【讨论】:

        猜你喜欢
        • 2012-05-28
        • 2020-01-30
        • 2020-09-09
        • 2023-03-26
        • 1970-01-01
        • 2011-11-13
        • 1970-01-01
        • 2014-10-24
        • 2013-08-03
        相关资源
        最近更新 更多