如何排除maven war插件生成的jar? [英] How to exclude jars generated by maven war plugin?

查看:213
本文介绍了如何排除maven war插件生成的jar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于传递依赖性,我的战争由xml-apis,xerces jars填充。
我尝试按照maven-war-plugin参考页面上的说明进行操作,但它无效。

Because of transitive dependencies, my wars are getting populated by xml-apis, xerces jars. I tried following the instructions on the reference page for maven-war-plugin but it is not working.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
      <packagingExcludes>WEB-INF/lib/xalan-2.6.0.jar,WEB-INF/lib/xercesImpl-2.6.2.jar,WEB-INF/lib/xml-apis-1.0.b2.jar,WEB-INF/lib/xmlParserAPIs-2.6.2.jar</packagingExcludes>
      <webXml>${basedir}/src/main/webapp/WEB-INF/web.xml</webXml>
      <warName>project1</warName>
      <warSourceDirectory>src/main/webapp</warSourceDirectory>
    </configuration>
</plugin>

我做错了什么?
如果重要的话,我发现我正在使用的maven-war-plugin版本为2.1-alpha-1

What am I doing wrong ? If it matters, I discovered that the maven-war-plugin I'm using is at version 2.1-alpha-1

推荐答案

您可以按照提供的标记这些依赖关系:

You can mark these dependencies as provided:

<dependency>
  <groupId>xerces</groupId>
  <artifactId>xerces</artifactId>
  <version>2.4.0</version>
  <scope>provided</scope>
</dependency>

这样maven会将它们添加到编译类路径中,但不会打包它们。假设它们存在于您的servlet容器中。

This way the maven will add them to the compilation classpath, but will not package them. It is assumed they exist in your servlet container.

查看有关maven范围的更多信息

See more about maven scopes here under "scope"

编辑
如果要删除课程通过传递依赖项添加,您可以将它们从依赖项中排除,如下所示:

Edit If you want to remove classes added via transitive dependencies you can exclude them from the dependency like this:

<dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring</artifactId>
        <version>2.5.6</version>
        <exclusions>
                <exclusion>
                        <groupId>commons-logging</groupId>
                        <artifactId>commons-logging</artifactId>
                </exclusion>
        </exclusions>
</dependency>

(取自这个答案

查看更多 here

这篇关于如何排除maven war插件生成的jar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆