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 Dev

Maven - How to exclude dependencies from generated JAR

From Dev

Exclude obfuscated jar from lib folder with ProGuard

From Dev

Make jar file from folder

From Dev

Gradle: Exclude file from Android assets folder

From Dev

How to exclude a file/folder from Build in MonoDevelop

From Dev

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

From Dev

rsync exclude a single file from the root folder

From Dev

Gradle - Exclude file from being packaged with jar

From Dev

Gradle - Exclude file from being packaged with jar

From Dev

Read a file from a jar file, the jar generated using netbeans

From Dev

Exclude file from jar as built by jar-with-dependencies

From Dev

Copying images from JAR file to a folder outside

From Dev

Compiling Java source file using classpath from generated jar file

From Dev

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

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 Dev

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

From Dev

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

From Dev

How to exclude resource file from spring boot jar?

From Dev

Gradle build: Exclude resources files from Spring Boot Jar file

From Java

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

From Dev

How to exclude target folder from maven source packages generated with mvn deploy?

From Dev

Unable to import file from ember-cli generated utils folder

From Dev

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

From Dev

Exclude Folder with Laravel File::allFiles

From Dev

Exclude file that matches in project folder

From Dev

How to add Maven dependency jar file from the lib folder

From Dev

Executing Jar file from command line with spaces in folder name

From Dev

Loading docx file from resources folder in runnable jar

Related Related

  1. 1

    Maven - How to exclude dependencies from generated JAR

  2. 2

    Exclude obfuscated jar from lib folder with ProGuard

  3. 3

    Make jar file from folder

  4. 4

    Gradle: Exclude file from Android assets folder

  5. 5

    How to exclude a file/folder from Build in MonoDevelop

  6. 6

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

  7. 7

    rsync exclude a single file from the root folder

  8. 8

    Gradle - Exclude file from being packaged with jar

  9. 9

    Gradle - Exclude file from being packaged with jar

  10. 10

    Read a file from a jar file, the jar generated using netbeans

  11. 11

    Exclude file from jar as built by jar-with-dependencies

  12. 12

    Copying images from JAR file to a folder outside

  13. 13

    Compiling Java source file using classpath from generated jar file

  14. 14

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

  15. 15

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

  16. 16

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

  17. 17

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

  18. 18

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

  19. 19

    How to exclude resource file from spring boot jar?

  20. 20

    Gradle build: Exclude resources files from Spring Boot Jar file

  21. 21

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

  22. 22

    How to exclude target folder from maven source packages generated with mvn deploy?

  23. 23

    Unable to import file from ember-cli generated utils folder

  24. 24

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

  25. 25

    Exclude Folder with Laravel File::allFiles

  26. 26

    Exclude file that matches in project folder

  27. 27

    How to add Maven dependency jar file from the lib folder

  28. 28

    Executing Jar file from command line with spaces in folder name

  29. 29

    Loading docx file from resources folder in runnable jar

HotTag

Archive