简体   繁体   中英

maven shade not creating fat jar with manifest

I am using maven 3.6.1 and maven shade plugin 2.3. I have copied the shade plugin part of the pom file below. The manifest is getting created when the jar is created but it does not reference the main class. I am creating the jar using the mvn package command. Any thoughts on how to fix this?

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

I had to run the package command as follows (ie with shade as target):

mvn clean package shade:shade

Removing the plugin from pluginManagement allows me to create the shaded jar using the following:

mvn clean package

In addition to the updated command line, I also had to add a <manifestEntries> section, like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM