m2e阴影蚀“项目主要工件不存在”

时间:2013-01-24 05:43:57

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

我正在尝试创建一个部署包,它将我的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.

此时我已经没想完了。

2 个答案:

答案 0 :(得分:10)

  

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

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

mvn package

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

答案 1 :(得分:3)

阴影插件试图在阴影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>