8

我正在尝试制作一个部署包,它将我的 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”,并勾选“Resolve Workspace artifacts”。

它失败了

--- 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.

此时我没有主意了。

4

2 回答 2

21

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

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

mvn package

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

于 2014-02-19T15:26:50.563 回答
7

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

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

这是一个例子:

<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>
于 2013-08-24T19:20:46.973 回答