How to create a jar without meta-inf folder in maven?

If I wanted to create a jar file without META-INF metadata using the jar utility, I can pass the -M switch, which will be:

   -M  do not create a manifest file for the entries

Please note that this is a function of the jar utility. If I use it, I get a jar without a META-INF folder and turn on MANIFEST, basically just an archive like jar with any files / directories that I inserted into it.

How can I do this using maven-jar-plugin? I need to do this to fit a different process. (They are expecting a jar with a very specific file / folder location, and I cannot have the META-INF folder in the root jar file.)

I have a configuration to create a jar file only on the right, and I don't want to mess with another plugin ...

+4
source share
2 answers

There is no way in maven-jar-plugin to disable manifest folder creation, but you can disable the maven descriptor directory as follows:

         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <addMavenDescriptor>false</addMavenDescriptor>
                    <manifest>
                        <addClasspath>false</addClasspath>
                    </manifest>
                </archive>
            </configuration>
        </plugin>

If you want to delete the META-INF folder, you can use maven-shade-plugin as follows:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <filters>
                            <filter>
                                <artifact>*:*</artifact>
                                <excludes>
                                    <exclude>META-INF/</exclude>
                                </excludes>
                            </filter>
                        </filters>
                    </configuration>
                </execution>
            </executions>
        </plugin>
+6
source

You can use maven-shade-pluginto achieve the desired effect:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.4.1</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <artifactSet>
                    <includes>
                        <include>${project.groupId}:${project.artifactId}</include>
                    </includes>
                </artifactSet>
                <filters>
                    <filter>
                        <artifact>*:*</artifact>
                        <excludes>
                            <exclude>META-INF/</exclude>
                        </excludes>
                    </filter>
                </filters>
            </configuration>
        </execution>
    </executions>
</plugin>

The configuration filters the META-INF directory and includes only the current project, so dependencies are not bound.

+4
source

All Articles