由于传递依赖关系,我的 war 被 xml-apis、xerces jars 填充。 我尝试按照 maven-war-plugin 引用页面上的说明进行操作,但它不起作用。
<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
最佳答案
您可以将这些依赖项标记为已提供:
<dependency>
<groupId>xerces</groupId>
<artifactId>xerces</artifactId>
<version>2.4.0</version>
<scope>provided</scope>
</dependency>
这样 maven 会将它们添加到编译类路径中,但不会打包它们。假定它们存在于您的 servlet 容器中。
查看更多关于 maven 作用域的信息 here在“范围”下
编辑 如果你想删除通过传递依赖添加的类,你可以像这样从依赖中排除它们:
<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>
(取自this answer)
查看更多 here
关于java - 如何排除 maven war 插件生成的 jars?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1031695/