【发布时间】:2010-11-21 07:20:44
【问题描述】:
如何过滤 /target/classes 中的某些类,使其不进入 /target/[webapp]/WEB-INF/classes?我希望它们编译到 /target/classes/ 但不是在最后的战争中。
【问题讨论】:
标签: java maven-2 jakarta-ee
如何过滤 /target/classes 中的某些类,使其不进入 /target/[webapp]/WEB-INF/classes?我希望它们编译到 /target/classes/ 但不是在最后的战争中。
【问题讨论】:
标签: java maven-2 jakarta-ee
这些课程有什么用?如果是用于测试的,可以在 src/test/java 中指定,然后在 test-compile 阶段编译成 target/test-classes,但不会包含在最终的战争中。
如果它们不是用于测试并且不包含在战争中,也许应该将它们重构到另一个项目中,以便您可以将其指定为依赖项(可能具有“提供”范围,因此它们不会是部署。
作为参考,您可以将战争配置为在打包时包含和排除资源。
以下示例将包含所有 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。
【讨论】:
您可以使用 TrueZIP Maven 插件 (http://mojo.codehaus.org/truezip-maven-plugin/)。
查看示例:
http://svn.codehaus.org/mojo/trunk/mojo/truezip-maven-plugin/src/it/
【讨论】:
假设您将它们放在可以使用 ant 模式定义的包中,您可能会很幸运
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<excludes>**/dontneed/*.class</excludes>
</configuration>
</plugin>
【讨论】:
使用当前版本的 maven-war-plugin (3.0.0) 这对我有用 -
<profile>
<id>abc</id>
...
<build>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<packagingExcludes>WEB-INF/classes/com/abc/pqr/ClassName.class</packagingExcludes>
</configuration>
</plugin>
</build>
</profile>
【讨论】: