我只需要一个依赖模块,但不需要它的依赖项

时间:2010-06-01 23:23:52

标签: maven-2 maven

在我的项目中,有一个spring XML配置,它使用ehcache来缓存方法返回。

xml片段:

    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>

但是在运行时,服务器抱怨找不到http://www.springmodules.org/schema/ehcache定义,我知道我必须在WEB-INF / lib目录中添加“spring-modules-cache.jar”。

但是我的项目是由maven维护的,如果我将“spring-modules-cache”添加到运行时依赖项中,它会为我的WAR文件带来很多依赖,用很多不必要的jar填充我的WAR。我只需要一个声明,而不是所有的依赖...

有没有办法告诉maven不要将其依赖项包含在项目中?

或者......换句话说,当打包WAR时,只需将另一个准备好的spring-modules-cache.jar复制到WEB-INF / lib,该怎么做?谢谢!

2 个答案:

答案 0 :(得分:2)

看看这个article - 基本上你需要使用排除

答案 1 :(得分:2)

如上所述,您可以使用排除机制,但这基本上意味着排除在依赖项pom中声明的每个运行时依赖项,这不仅是一种痛苦,而且是脆弱的,因为您必须继续跟踪依赖项的pom以保留您的列表排除最新情况。

另一种方法是将依赖项标记为<scope>provided</scope>,然后使用dependency:copy插件目标将依赖项自行复制到“target”下的war构建目录。默认情况下会内置战争 ${project.build.directory}/${project.build.finalName}。有关详细信息,请参阅war plugin

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>
相关问题