blob: 74a4e71dac3b451c66ff060330c4184e9d5d39c2 [file] [log] [blame]
------
Including and Excluding Files From the WAR
------
Dennis Lundberg
------
2011-11-21
------
~~ Licensed to the Apache Software Foundation (ASF) under one
~~ or more contributor license agreements. See the NOTICE file
~~ distributed with this work for additional information
~~ regarding copyright ownership. The ASF licenses this file
~~ to you under the Apache License, Version 2.0 (the
~~ "License"); you may not use this file except in compliance
~~ with the License. You may obtain a copy of the License at
~~
~~ http://www.apache.org/licenses/LICENSE-2.0
~~
~~ Unless required by applicable law or agreed to in writing,
~~ software distributed under the License is distributed on an
~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~~ KIND, either express or implied. See the License for the
~~ specific language governing permissions and limitations
~~ under the License.
~~ NOTE: For help with the syntax of this file, see:
~~ http://maven.apache.org/doxia/references/apt-format.html
Including and Excluding Files From the WAR
It is possible to include or exclude certain files from the WAR file, by using
the <<<\<packagingIncludes\>>>> and <<<\<packagingExcludes\>>>> configuration
parameters. They each take a comma-separated list of Ant file set patterns.
You can use wildcards such as <<<**>>> to indicate multiple directories and
<<<*>>> to indicate an optional part of a file or directory name.
Here is an example where we exclude all JAR files from <<<WEB-INF/lib>>>:
+-----------------+
<project>
...
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>${project.version}</version>
<configuration>
<packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
+-----------------+
Sometimes even such wildcards are not enough. In these cases you can use
regular expressions with the <<<%regex[]>>> syntax. Here is a real life use
case in which this is used. In this example we want to exclude any
commons-logging and log4j JARs, but we do not want to exclude the
log4j-over-slf4j JAR. So we want to exclude <<<log4j-\<version\>.jar>>> but
keep the <<<log4j-over-slf4j-\<version\>.jar>>>.
+-----------------+
<project>
...
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>${project.version}</version>
<configuration>
<!--
Exclude JCL and LOG4J since all logging should go through SLF4J.
Note that we're excluding log4j-<version>.jar but keeping
log4j-over-slf4j-<version>.jar
-->
<packagingExcludes>
WEB-INF/lib/commons-logging-*.jar,
%regex[WEB-INF/lib/log4j-(?!over-slf4j).*.jar]
</packagingExcludes>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
+-----------------+
If you have more real life examples of using regular expressions, we'd like to
know about them. Please file an issue in
{{{../issue-tracking.html}our issue tracker}} with your configuration, so we
can expand this page.