[英]How to exclude classes from a packaged webapp with maven
如何過濾進入/ target / [webapp] / WEB-INF / classes的/ target / classes中的某些類? 我希望將它們編譯到/ target / classes /中,但不要在最后一戰中使用。
這些課程是干什么的? 如果要進行測試,則可以在src / test / java中指定它們,然后在測試編譯階段將它們編譯為target / test-class,但不會包含在最終戰爭中。
如果它們不用於測試並且不包含在戰爭中,則也許應該將它們重構到另一個項目中,以便您可以將其指定為依賴項(也許具有“提供的”范圍,因此將不會部署它們)。
作為參考,您可以配置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插件文檔 。
您可以使用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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.