How to really & fully exclude a package from a jar?

Withheld

Having this dependencies section in my pom.xml:

<dependencies>
  <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>3.8.1</version>
    <scope>test</scope>
  </dependency>


  <dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-frontend-jaxws</artifactId>
    <version>2.7.1</version>
    <type>jar</type>
    <scope>runtime</scope>
  </dependency>
  <dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-transports-http</artifactId>
    <version>2.7.1</version>
    <type>jar</type>
    <scope>runtime</scope>
  </dependency>
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>3.0.7.RELEASE</version>
  </dependency>


  <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.26</version>
  </dependency>
  <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>4.2.6.Final</version>
  </dependency>
  <dependency> 
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-api</artifactId>
    <version>2.7.1</version>
    <exclusions>
      <exclusion>
        <groupId>org.apache.geronimo.specs</groupId>
        <artifactId>geronimo-javamail_1.4_spec</artifactId>
      </exclusion>
    </exclusions> 
  </dependency>
  <dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-transports-http</artifactId>
    <version>2.7.1</version>
    <type>jar</type>
  </dependency>

  <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
  </dependency>

  <dependency> 
    <groupId>javax.mail</groupId>
    <artifactId>mail</artifactId>
    <version>1.4.1</version>
  </dependency>
  <dependency>
    <groupId>javax.activation</groupId>
    <artifactId>activation</artifactId>
    <version>1.1.1</version>
  </dependency>

</dependencies>

I expected the geronimo-javamail_1.4_spec package to be excluded from the build and, indeed, when I run mvn dependency:tree, it is no longer listed there.

However, when running the resulting jar, the JarClassLoader still complains about javax/mail classes being hidden by the geronimo ones...

Sure enough, when I examine the jar via 7-zip, I see that geronimo-javamail_1.4_spec-1.7.1.jar is still there (comes as part of the org.apache.cxf:cxf-api:jar:2.7.1:compile package).

How do I fully exclude a package? i.e. not only remove it from the dependency tree, but also not include it at all in the resulting jar?


Adding the onejar relevant xml per the comment below:

<plugin>
  <groupId>com.jolira</groupId>
  <artifactId>onejar-maven-plugin</artifactId>
  <version>1.4.4</version>
  <executions>
    <execution>
      <configuration>
        <mainClass>com.corp.dept.proj.myclient</mainClass>
        <onejarVersion>0.97</onejarVersion>
        <attachToBuild>true</attachToBuild>
        <!-- Optional, default is "onejar" -->
        <classifier>onejar</classifier>
      </configuration>
      <goals>
        <goal>one-jar</goal>
      </goals>
    </execution>
  </executions>
</plugin>

Adding the output of the mvn dependency after the scope & debug options were specified per the answer below:

C:\Users\withheld\workspace\myclient>mvn dependency:tree -Dscope=runtime -Ddebug=true
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'dependency'.
[INFO] org.apache.maven.plugins: checking for updates from onejar-maven-plugin.googlecode.com
[INFO] org.codehaus.mojo: checking for updates from onejar-maven-plugin.googlecode.com
[INFO] ------------------------------------------------------------------------
[INFO] Building myclient
[INFO]    task-segment: [dependency:tree]
[INFO] ------------------------------------------------------------------------
Downloading: http://repo1.maven.org/maven2/com/oracle/ojdbc14/14/ojdbc14-14.pom
[INFO] Unable to find resource 'com.oracle:ojdbc14:pom:14' in repository central (http://repo1.maven.org/maven2)
[INFO] [dependency:tree {execution: default-cli}]
[INFO] com.corp.dept.proj:myclient:jar:0.0.6
[INFO] +- junit:junit:jar:3.8.1:test
[INFO] +- com.oracle:ojdbc14:jar:14:compile
[INFO] +- org.apache.cxf:cxf-rt-frontend-jaxws:jar:2.7.1:runtime
[INFO] |  +- xml-resolver:xml-resolver:jar:1.2:runtime
[INFO] |  +- asm:asm:jar:3.3.1:runtime
[INFO] |  +- org.apache.cxf:cxf-rt-bindings-soap:jar:2.7.1:runtime
[INFO] |  |  \- org.apache.cxf:cxf-rt-databinding-jaxb:jar:2.7.1:runtime
[INFO] |  +- org.apache.cxf:cxf-rt-bindings-xml:jar:2.7.1:runtime
[INFO] |  +- org.apache.cxf:cxf-rt-frontend-simple:jar:2.7.1:runtime
[INFO] |  \- org.apache.cxf:cxf-rt-ws-addr:jar:2.7.1:runtime
[INFO] |     \- org.apache.cxf:cxf-rt-ws-policy:jar:2.7.1:runtime
[INFO] |        \- org.apache.neethi:neethi:jar:3.0.2:runtime
[INFO] +- org.apache.cxf:cxf-rt-transports-http:jar:2.7.1:compile
[INFO] |  \- org.apache.cxf:cxf-rt-core:jar:2.7.1:compile
[INFO] |     \- com.sun.xml.bind:jaxb-impl:jar:2.1.13:compile
[INFO] +- org.springframework:spring-web:jar:3.0.7.RELEASE:compile
[INFO] |  +- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  +- org.springframework:spring-beans:jar:3.0.7.RELEASE:compile
[INFO] |  +- org.springframework:spring-context:jar:3.0.7.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-aop:jar:3.0.7.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-expression:jar:3.0.7.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-asm:jar:3.0.7.RELEASE:compile
[INFO] |  \- org.springframework:spring-core:jar:3.0.7.RELEASE:compile
[INFO] |     \- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] +- mysql:mysql-connector-java:jar:5.1.26:compile
[INFO] +- org.hibernate:hibernate-core:jar:4.2.6.Final:compile
[INFO] |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  +- org.jboss.logging:jboss-logging:jar:3.1.0.GA:compile
[INFO] |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:jar:1.0.1.Final:compile
[INFO] |  +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile
[INFO] |  +- org.hibernate.common:hibernate-commons-annotations:jar:4.0.2.Final:compile
[INFO] |  \- org.javassist:javassist:jar:3.15.0-GA:compile
[INFO] +- org.apache.cxf:cxf-api:jar:2.7.1:compile
[INFO] |  +- org.codehaus.woodstox:woodstox-core-asl:jar:4.1.4:runtime
[INFO] |  |  \- org.codehaus.woodstox:stax2-api:jar:3.1.1:runtime
[INFO] |  +- org.apache.ws.xmlschema:xmlschema-core:jar:2.0.3:compile
[INFO] |  \- wsdl4j:wsdl4j:jar:1.6.2:compile
[INFO] +- javax.servlet:servlet-api:jar:2.5:compile
[INFO] +- javax.mail:mail:jar:1.4.1:compile
[INFO] \- javax.activation:activation:jar:1.1.1:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4 seconds
[INFO] Finished at: Thu Apr 24 11:22:49 EDT 2014
[INFO] Final Memory: 20M/49M
[INFO] ------------------------------------------------------------------------
rompetroll

The onejar plugin adds all artifacts from maven's runtime scope, as it should be.

The command mvn dependency:tree does not seem to list all runtime dependencies properly though. Could be a bug, I don't know why.

Luckily, by adding a few parameters you can have all runtime scope dependencies listed.

mvn dependency:tree -Dscope=runtime -Ddebug=true

This will show that cxf-rt-core also has geronimo-javamail as dependency. So, your solution would be to explicitly add the core jar with an exclusion to your dependencies.

    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-core</artifactId>
        <version>2.7.1</version>
        <exclusions>
            <exclusion>
                <groupId>org.apache.geronimo.specs</groupId>
                <artifactId>geronimo-javamail_1.4_spec</artifactId>
            </exclusion>
        </exclusions> 
    </dependency>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Gradle: How to exclude a particular package from a jar?

From Dev

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

From Dev

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

From Dev

How do I exclude a package from an imported JAR for a project in Eclipse?

From Dev

Gradle: How to exclude javax.realtime package from JScience jar dependency (Multiple dex define)

From Dev

OpenEJB: How to exclude jar from module search?

From Dev

How to exclude modules or groups in a jar from Gradle?

From Dev

Maven - How to exclude dependencies from generated JAR

From Dev

How to exclude a subdirectory and contents from a nuget package

From Dev

How to exclude package from scoverage in maven

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

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

From Dev

How to fully remove the eclipse package?

From Dev

Exclude package from external JAR in Android Studio during Gradle build process

From Dev

maven: exclude jar from JDK

From Dev

Exclude resources from dependency jar

From Dev

How to exclude a maven test scope from package phase?

From Dev

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

From Dev

How to exclude a single file from package with setuptools and setup.py

From Dev

How to Exclude a T4 Template from a NuGet Package

From Dev

How to exclude a package from apt-get autoremove?

From Dev

How to exclude package-info.java files from dex?

From Dev

Exclude a package from updating in composer

From Dev

Exclude Package From Gradle Dependency

From Dev

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

From Dev

How do I remove a package from android.jar?

From Dev

How to get package data [jar file name] from stack trace?

From Dev

How to remove/install a package that is not fully installed?

Related Related

  1. 1

    Gradle: How to exclude a particular package from a jar?

  2. 2

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

  3. 3

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

  4. 4

    How do I exclude a package from an imported JAR for a project in Eclipse?

  5. 5

    Gradle: How to exclude javax.realtime package from JScience jar dependency (Multiple dex define)

  6. 6

    OpenEJB: How to exclude jar from module search?

  7. 7

    How to exclude modules or groups in a jar from Gradle?

  8. 8

    Maven - How to exclude dependencies from generated JAR

  9. 9

    How to exclude a subdirectory and contents from a nuget package

  10. 10

    How to exclude package from scoverage in maven

  11. 11

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

  12. 12

    How to exclude resource file from spring boot jar?

  13. 13

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

  14. 14

    How to fully remove the eclipse package?

  15. 15

    Exclude package from external JAR in Android Studio during Gradle build process

  16. 16

    maven: exclude jar from JDK

  17. 17

    Exclude resources from dependency jar

  18. 18

    How to exclude a maven test scope from package phase?

  19. 19

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

  20. 20

    How to exclude a single file from package with setuptools and setup.py

  21. 21

    How to Exclude a T4 Template from a NuGet Package

  22. 22

    How to exclude a package from apt-get autoremove?

  23. 23

    How to exclude package-info.java files from dex?

  24. 24

    Exclude a package from updating in composer

  25. 25

    Exclude Package From Gradle Dependency

  26. 26

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

  27. 27

    How do I remove a package from android.jar?

  28. 28

    How to get package data [jar file name] from stack trace?

  29. 29

    How to remove/install a package that is not fully installed?

HotTag

Archive