专家阴影不会创建带有清单的胖子

时间:2019-05-28 14:57:58

标签: java maven

我正在使用Maven 3.6.1和Maven Shade插件2.3。我已经复制了下面pom文件的shade插件部分。创建jar时将创建清单,但清单没有引用主类。我正在使用 mvn包命令创建jar。关于如何解决此问题有任何想法吗?

        <plugin>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <createDependencyReducedPom>true</createDependencyReducedPom>
                <transformers>
                    <transformer
                            implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                    <transformer
                            implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                        <mainClass>com.abc.someclass</mainClass>
                    </transformer>
                </transformers>
                <!-- exclude signed Manifests -->
                <filters>
                    <filter>
                        <artifact>*:*</artifact>
                        <excludes>
                            <exclude>META-INF/*.SF</exclude>
                            <exclude>META-INF/*.DSA</exclude>
                            <exclude>META-INF/*.RSA</exclude>
                        </excludes>
                    </filter>
                </filters>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

2 个答案:

答案 0 :(得分:0)

我必须按以下方式运行package命令(即以阴影作为目标):

mvn clean package shade:shade

从pluginManagement中删除插件后,我可以使用以下方法创建阴影罐:

mvn clean package

答案 1 :(得分:0)

除了更新的命令行之外,我还必须添加一个<manifestEntries>部分,如下所示:

    <artifactId>maven-shade-plugin</artifactId>
    <version>3.2.3</version>
    <configuration>
        <shadedArtifactAttached>false</shadedArtifactAttached>
        <transformers>
            <transformer
                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                <mainClass>org.foo.bar.Main</mainClass>
                <manifestEntries>
                    <Main-Class>org.foo.bar.Main</Main-Class>
                </manifestEntries>
            </transformer>
    ...