tags:

views:

38

answers:

2

In my project , there is a spring XML config that utilizes ehcache to cache method returns.

xml snippet :

    http://www.springmodules.org/schema/ehcache http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd

  <ehcache:config configLocation="classpath:ehcache.xml"/>

  <ehcache:proxy id="explainRetriever" refId="explainRetrieverImpl">
    <ehcache:caching methodName="get*" cacheName="explainCache"/>
  </ehcache:proxy>

but in runtime , server complains it cannot find definitions of http://www.springmodules.org/schema/ehcache , I know I have to add "spring-modules-cache.jar" to WEB-INF/lib directory.

But my project is maintained by maven , if I add "spring-modules-cache" to the runtime dependency , it will bring a lot of dependencies to my WAR file , filling my WAR with a lot of unnecessary jars. I just need one declaration in it , not all of its dependencies ...

Is there any way to tell maven not to include its dependencies to the project ?

Or ... another way , when packaging WAR , just copy another prepared spring-modules-cache.jar to WEB-INF/lib , how to do this ? Thanks !

+2  A: 

Have a look at this article - basically you need to use exclusions.

Bozhidar Batsov
+2  A: 

As mentioned, you can use the exclusions mechanism, but that basically means excluding every runtime dependency declared in the dependency's pom, which is not only a pain, but fragile, since you have to keep tracking the dependency's pom to keep your list of exclusions up to date.

An alternative is to mark the dependency as <scope>provided</scope> and then copy the dependency yourself to the war construction directory under 'target' using the dependency:copy plugin goal. By default a war is built in ${project.build.directory}/${project.build.finalName}. See the war plugin for details.

E.g.

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>copy</id>
            <phase>package</phase>
            <goals>
              <goal>copy</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>org.springmodules</groupId>
                  <artifactId>spring-modules-cache</artifactId>
                  <version>0.8</version>
                  <type>jar</type>
                  <overWrite>true</overWrite>
                  <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/lib</outputDirectory>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
        </executions>
      </plugin>
mdma
Wow , thanks a lot !!!It solves my problem neatly...
smallufo
You're welcome. Good to see that the hours spent slaving over a hot maven have come to something good!
mdma