Exclude META-INF/maven folder from the generated jar file

Coder_sLaY :

I am trying to create a jar file which has all the necessary classes extracted within the jar. But for few dependent jar like log4j, it creates some folders inside META-INF/maven/*. I have a limitation that the server in which I will be placing the generated jar file will not have Internet connectivity. So if there is any content in this META-INF/maven/* folder then it gives me an error.

My maven descriptor looks like the following

<build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <addMavenDescriptor>false</addMavenDescriptor>
                </archive>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <minimizeJar>true</minimizeJar>
                <finalName>myclient</finalName>
            </configuration>
        </plugin>
    </plugins>
</build>

I am able to extract the required class files in the generated jar but the maven folder is still getting generated under META-INF. I have to manually delete the folder to make everything work. Please advice on how to automate this removal of maven folder from the generated jar file.

Tunaki :

You can use filters inside the maven-shade-plugin configuration to exclude everything that is under META-INF/maven for every artifact:

<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>
                <filters>
                    <filter>
                        <artifact>*:*</artifact>
                        <excludes>
                            <exclude>META-INF/maven/**</exclude>
                        </excludes>
                    </filter>
                </filters>
            </configuration>
        </execution>
    </executions>
</plugin>

A solution for the maven-jar-plugin can be found here.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Maven: Exclude "META-INF/maven" folder from JAR

From Dev

Maven - How to exclude dependencies from generated JAR

From Java

Exclude obfuscated jar from lib folder with ProGuard

From Dev

Gradle: Exclude file from Android assets folder

From Dev

Possible to ignore/exclude file/folder from .editorconfig?

From Dev

rsync exclude a single file from the root folder

From Java

Gradle - Exclude file from being packaged with jar

From Dev

Exclude Test folder and Resources from Gradle Jar build

From Java

read from a file that is in the same folder as the .jar file

From Dev

C# copy last file from a folder into another generated folder

From Dev

Loading Jar File From Different Folder

From Java

Access a file from a JAR in the same folder

From Dev

Gradle: Exclude file from resourses and add it from different folder

From Dev

Compiling Java source file using classpath from generated jar file

From Java

Exclude folder from WAR file in Netbeans 6+

From Dev

Nginx - Exclude specific file or folder from logging to access.log

From Dev

How to exclude a file\folder from SVN monitoring in Jenkins build

From

How to exclude file only from root folder in Git

From Dev

Eclipse - exclude file / folder from triggering workspace refresh after build

From Java

Gradle build: Exclude resources files from Spring Boot Jar file

From Java

Spring Boot Maven Plugin: Exclude properties file from final jar

From Java

How to exclude resource file from spring boot jar?

From

In an Android Gradle build, how to exclude dependencies from an included jar file?

From Java

How to include a config file in the "META-INF/services" folder of a JAR using Maven

From Dev

Adding a file from file system to a specific folder inside a jar

From Dev

Search for latest version of jar file in folder and run it from batch file

From Dev

Delete file from sub folder but want to exclude one sub folder-batch file

From Dev

PowerShell GetChildItem exclude file type in base folder but include same file type from sub folder

From Dev

Exclude file that matches in project folder

Related Related

  1. 1

    Maven: Exclude "META-INF/maven" folder from JAR

  2. 2

    Maven - How to exclude dependencies from generated JAR

  3. 3

    Exclude obfuscated jar from lib folder with ProGuard

  4. 4

    Gradle: Exclude file from Android assets folder

  5. 5

    Possible to ignore/exclude file/folder from .editorconfig?

  6. 6

    rsync exclude a single file from the root folder

  7. 7

    Gradle - Exclude file from being packaged with jar

  8. 8

    Exclude Test folder and Resources from Gradle Jar build

  9. 9

    read from a file that is in the same folder as the .jar file

  10. 10

    C# copy last file from a folder into another generated folder

  11. 11

    Loading Jar File From Different Folder

  12. 12

    Access a file from a JAR in the same folder

  13. 13

    Gradle: Exclude file from resourses and add it from different folder

  14. 14

    Compiling Java source file using classpath from generated jar file

  15. 15

    Exclude folder from WAR file in Netbeans 6+

  16. 16

    Nginx - Exclude specific file or folder from logging to access.log

  17. 17

    How to exclude a file\folder from SVN monitoring in Jenkins build

  18. 18

    How to exclude file only from root folder in Git

  19. 19

    Eclipse - exclude file / folder from triggering workspace refresh after build

  20. 20

    Gradle build: Exclude resources files from Spring Boot Jar file

  21. 21

    Spring Boot Maven Plugin: Exclude properties file from final jar

  22. 22

    How to exclude resource file from spring boot jar?

  23. 23

    In an Android Gradle build, how to exclude dependencies from an included jar file?

  24. 24

    How to include a config file in the "META-INF/services" folder of a JAR using Maven

  25. 25

    Adding a file from file system to a specific folder inside a jar

  26. 26

    Search for latest version of jar file in folder and run it from batch file

  27. 27

    Delete file from sub folder but want to exclude one sub folder-batch file

  28. 28

    PowerShell GetChildItem exclude file type in base folder but include same file type from sub folder

  29. 29

    Exclude file that matches in project folder

HotTag

Archive