如何过滤/target/classes 中的某些类,使其不进入/target/[webapp]/WEB-INF/classes?我希望它们被编译到/target/classes/但不是在最终 war 中。
最佳答案
这些类(class)有什么用?如果是测试用的,可以在src/test/java中指定,然后在test-compile阶段会编译成target/test-classes,但不会包含在final war中。
如果它们不用于测试并且不被包含在 war 中,也许它们应该被重构到另一个项目中,这样你就可以将它指定为一个依赖项(也许具有“提供的”范围,这样它们就不会被已部署。
作为引用,您可以将 war 配置为在打包时包含和排除资源。
以下示例将包括所有 jpg,但不包括 image2 子文件夹中的资源:
<configuration>
<webResources>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>resource2</directory>
<!-- the list has a default value of ** -->
<includes>
<include>**/*.jpg</include>
<includes>
<excludes>
<exclude>**/image2</exclude>
</excludes>
</resource>
</webResources>
</configuration>
参见 war plugin documentation了解更多详情。
关于java - 如何使用 Maven 从打包的 Web 应用程序中排除类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1305811/