Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove .jar file from a war that is overlaid by maven dependency

I have a maven3 webapp (war) project that has 2 dependencies. One is a jar (ehcache) and the other a war dependency (a 3rd party lib that I have no control over).

The 3rd party war dependency has a dependency on much earlier version of ehcache which is clashing with the later version I need to use.

The following steps occur during a package of my app.

  1. My ehcache jar is copied to /WEB-INF/lib/
  2. The .war dependency which also includes ehcache is built and overlaid on top of my target
  3. Final .war file is created from target

No matter what I do, the war always includes the earlier version of ehcache. I've even tried writing an ant script which I execute via maven-antrun-plugin that removes the .jar file from the target directory. However, this always gets done before the .war dependency is overlaid.

Does anyone know how I can exclude/remove the earlier version of ehcache?

like image 358
Joel Avatar asked Jun 14 '12 15:06

Joel


1 Answers

You'll probably need to exclude the ehcache jar by filename from your overlay. If you aren't already declaring an explicit overlay for your dependent war, you'll have to do that too in the war plugin configuration:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-war-plugin</artifactId>
      <version>2.2</version>
      <configuration>
        <overlays>
          <overlay>
            <groupId>your.thirdparty.war.groupId</groupId>
            <artifactId>your.thirdparty.war.artifactId</artifactId>
            <excludes>
              <exclude>WEB-INF/lib/ehcache*.jar</exclude>
            </excludes>
          </overlay>
        </overlays>
      </configuration>
    </plugin>
  </plugins>
</build>
like image 53
matts Avatar answered Nov 09 '22 10:11

matts