How can I exclude some packages (within a JAR) from a Maven dependency?

B255

I am depending on a library in my Maven project and I find that the library's JAR contains some packages which cause my application to fail. I believe the library should still work if I can somehow exclude these packages, but I would like to do this via Maven, rather than by hacking the JAR file myself. Is there a way to do this with Maven?

M Anouti

You can take a look at the maven-shade-plugin. An example is shown in the official docs.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.3</version>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
        <configuration>
          <filters>
            <filter>
              <artifact>junit:junit</artifact>
              <includes>
                <include>junit/framework/**</include>
                <include>org/junit/**</include>
              </includes>
              <excludes>
                <exclude>org/junit/experimental/**</exclude>
                <exclude>org/junit/runners/**</exclude>
              </excludes>
            </filter>
            <filter>
              <artifact>*:*</artifact>
              <excludes>
                <exclude>META-INF/*.SF</exclude>
                <exclude>META-INF/*.DSA</exclude>
                <exclude>META-INF/*.RSA</exclude>
              </excludes>
            </filter>
          </filters>
        </configuration>
      </execution>
    </executions>
  </plugin>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to use maven assembly plugin to exclude a package from dependency jar?

From Dev

Apache MAVEN: How can I specify a jar dependency from a non standard repository without a pom in the repo?

From Dev

How can I include a set of jar's as a single dependency in Maven?

From Dev

How can I remove maven dependency jar in Eclipse

From Dev

Can i select the only packages I used within my maven dependecies to export a runnable jar in eclipse?

From Dev

How can I exclude from Gradle dependency lists after the fact?

From Dev

How to exclude a package from a jar (with maven)

From Dev

Maven - How to exclude dependencies from generated JAR

From Dev

Webpack - how can I identify and exclude some package from rendering?

From Dev

How do I exclude java files from a jar in maven-jar-plugin?

From Dev

Exclude resources from dependency jar

From Dev

How can I access a class from a external maven dependency in GWT?

From Dev

maven-dependency-plugin: exclude .jar files

From Dev

Exclude packages while generating sources jar in Maven

From Dev

How to exclude project dependency from classpath used by maven plugin

From Dev

maven: exclude jar from JDK

From Dev

maven: how to build the dependency from source.jar to jar files and put the jar file as it dependency?

From Dev

How can I add JDT as a Maven dependency?

From Dev

How can I add LIRE dependency to Maven?

From Dev

Maven assembly or shade plugin - How to exclude sources from jar?

From Dev

I wish to exclude some class files from my jar. I am using maven-assembly-plugin. It still adds the files. I dont get any error

From Dev

How can I load an xml resource file from within an executible Jar file and save it to the folder the jar is located in?

From Dev

How can I load an xml resource file from within an executible Jar file and save it to the folder the jar is located in?

From Dev

How to exclude some maven project from sonar analysis

From Dev

how to add jar dependency in maven?

From Dev

How can I exclude SKAdvisorResources.bundle from being copied within the app?

From Dev

How to add Maven dependency jar file from the lib folder

From Dev

Maven: exclude dependency from shade plugin

From Dev

How can I use a Maven project as a dependency to another Maven project?

Related Related

  1. 1

    How to use maven assembly plugin to exclude a package from dependency jar?

  2. 2

    Apache MAVEN: How can I specify a jar dependency from a non standard repository without a pom in the repo?

  3. 3

    How can I include a set of jar's as a single dependency in Maven?

  4. 4

    How can I remove maven dependency jar in Eclipse

  5. 5

    Can i select the only packages I used within my maven dependecies to export a runnable jar in eclipse?

  6. 6

    How can I exclude from Gradle dependency lists after the fact?

  7. 7

    How to exclude a package from a jar (with maven)

  8. 8

    Maven - How to exclude dependencies from generated JAR

  9. 9

    Webpack - how can I identify and exclude some package from rendering?

  10. 10

    How do I exclude java files from a jar in maven-jar-plugin?

  11. 11

    Exclude resources from dependency jar

  12. 12

    How can I access a class from a external maven dependency in GWT?

  13. 13

    maven-dependency-plugin: exclude .jar files

  14. 14

    Exclude packages while generating sources jar in Maven

  15. 15

    How to exclude project dependency from classpath used by maven plugin

  16. 16

    maven: exclude jar from JDK

  17. 17

    maven: how to build the dependency from source.jar to jar files and put the jar file as it dependency?

  18. 18

    How can I add JDT as a Maven dependency?

  19. 19

    How can I add LIRE dependency to Maven?

  20. 20

    Maven assembly or shade plugin - How to exclude sources from jar?

  21. 21

    I wish to exclude some class files from my jar. I am using maven-assembly-plugin. It still adds the files. I dont get any error

  22. 22

    How can I load an xml resource file from within an executible Jar file and save it to the folder the jar is located in?

  23. 23

    How can I load an xml resource file from within an executible Jar file and save it to the folder the jar is located in?

  24. 24

    How to exclude some maven project from sonar analysis

  25. 25

    how to add jar dependency in maven?

  26. 26

    How can I exclude SKAdvisorResources.bundle from being copied within the app?

  27. 27

    How to add Maven dependency jar file from the lib folder

  28. 28

    Maven: exclude dependency from shade plugin

  29. 29

    How can I use a Maven project as a dependency to another Maven project?

HotTag

Archive