Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

maven

jar

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

   -M  do not create a manifest file for the entries

Note that this is a feature of the jar utility. If I use it, I will get a jar without the META-INF folder and included MANIFEST, basically just an archive of type jar with whatever files/directories I put in it.

How do I do this with the maven-jar-plugin? I need to do this to conform to another process. (They expect a jar with very specific file/folder layout and I cannot have a META-INF folder at the root of the jar file.)

I've got the configuration to create the jar file just right and I don't want to mess with another plugin...

like image 817
niken Avatar asked Dec 06 '22 18:12

niken


1 Answers

In maven-jar-plugin there is no option to disable creation of manifest folder, but you can disable the maven descriptor directory like this :

         <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 absolutely you want to delete the META-INF folder you can use maven-shade-plugin like this :

        <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>
like image 166
Joy_ Avatar answered Dec 09 '22 14:12

Joy_