------ Overlays ------ Pete Marvin King Stephane Nicoll ------ 12 Augustus 2007 ~~ Copyright 2006 The Apache Software Foundation. ~~ ~~ Licensed 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/guides/mini/guide-apt-format.html Overlays Overlays are meant to share common resources accross multiple web applications. In general, all dependencies of a war project are collected in <<>> except for war artifacts that are overlayed on the war source. In previous versions of the war plugin, no configuration was necessary. This is still the case if you are happy with the default settings. However, if you need more control, read on! * Overlays at a glance To demonstrate, given a project structure +-----------------+ . |-- pom.xml `-- src `-- main |-- java | `-- com | `-- example | `-- projects | `-- SampleAction.java |-- resources | |-- images | | `-- sampleimage.jpg | `-- sampleresource `-- webapp |-- WEB-INF | `-- web.xml |-- index.jsp `-- jsp `-- websource.jsp +-----------------+ which depends on <<>>. +-----------------+ documentedprojectdependency-1.0-SNAPSHOT.war |-- META-INF | |-- MANIFEST.MF | `-- maven | `-- com.example.projects | `-- documentedprojectdependency | |-- pom.properties | `-- pom.xml |-- WEB-INF | |-- classes | | |-- com | | | `-- example | | | `-- projects | | | `-- SampleActionDependency.class | | |-- images | | | `-- sampleimage-dependency.jpg | `-- web.xml |-- index-dependency.jsp +-----------------+ Assuming that you've declared the war artifact as a dependency in your <<>>. +-----------------+ [...] com.example.projects documentedprojectdependency 1.0-SNAPSHOT war runtime [...] [...] +-----------------+ the resulting war would end up like this +-----------------+ |-- META-INF | |-- MANIFEST.MF | `-- maven | `-- com.example.projects | |-- documentedproject | | |-- pom.properties | | `-- pom.xml | `-- documentedprojectdependency | |-- pom.properties | `-- pom.xml |-- WEB-INF | |-- classes | | |-- com | | | `-- example | | | `-- projects | | | |-- SampleAction.class | | | `-- SampleActionDependency.class | | |-- images | | | |-- sampleimage-dependency.jpg | | | `-- sampleimage.jpg | `-- web.xml |-- index-dependency.jsp |-- index.jsp |-- jsp | `-- websource.jsp +-----------------+ * Overlay types The war plugin handles both <> and <> artifacts. However, for backard compatibility reason, zip overlays are handled only if they are defined explicitely in the plugin's configuration. * Configuring Overlays The {overlay} element can be configured as follows: * <> - sets the id of the overlay. If none is provided, the war plugin will generate one. * <> - sets the groupId of the overlay artifact you want to configure. * <> - sets the artifactId of the overlay artifact you want to configure. * <> - sets the classifier of the overlay artifact you want to configure if multiple artifacts matches the groupId/artifact. * <> - sets the files to include. By default, all files are included. * <> - sets the files to exclude. By default, the <<>> directory is excluded. * <> - sets the target relative path in the webapp structure, which is only available for <> overlays. By default, the content of the overlay is added in the root structure of the webapp. * <> - set to true to skip this overlay. Default is false. For instance, to exclude the <<>> of our <<>> war overlay above: +-----------------+ [...] org.apache.maven.plugins maven-war-plugin com.example.projects documentedprojectdependency images/sampleimage-dependency.jpg [...] +-----------------+ * Overlays packaging Overlays are applied with a first-win strategy (hence if a file has been copied by an overlay, it won't be copied anymore). Overlays are applied in the order in which they are defined in the <<>> configuration. If no configuration is provided, the order in which they are defined in the dependencies is used (warning: this is not deterministic, especially if you have overlays as transitive dependencies). In case of a mixed situation (e.g. configured overlays and non)configured overlays), non-configured overlays are added after configured overlays. By default, the source of the project (<<>> the current build) is added first (e.g. before any overlay is applied). The current build is defined as a special overlay with no <<>>, <<>>. If overlays need to be applied first, simply configure the current build after those overlays. For instance, if <<>> from the <<>> group is a dependency of the project and needs to be applied before the projec's source, do as follows: +-----------------+ [...] org.apache.maven.plugins maven-war-plugin com.example.projects my-webapp [...] +-----------------+ Note that in the scenario above, any other overlay will be applied afther the current build since they have not been configured in the <<>> section. To perform an even fine grained overwriting policy, overlays can be packaged multiple times with different includes/excludes. For instance if the <<>> file of the overlay <<>> <> be set in the webapp but other files can be controlled the regular way, define two overlays configuration for <<>>: +-----------------+ [...] org.apache.maven.plugins maven-war-plugin my-webapp-index.jsp com.example.projects my-webapp index.jsp my-webapp com.example.projects my-webapp [...] +-----------------+ * Overlay global settings The following settings can be specified globally and modify further the way overlays are applied. * <> - sets the default includes to apply to all overlays. Any overlay that has no specific <<>> section inherit this settings by default. +-----------------+ [...] org.apache.maven.plugins maven-war-plugin **/IncludeME,**/images [...] +-----------------+ * <> - sets the default excludes to apply to all overlays. Any overlay that has no specific <<>> section inherit this settings by default. +-----------------+ [...] org.apache.maven.plugins maven-war-plugin WEB-INF/web.xml,index.* [...] +-----------------+ * <> - sets the directory where overlays will be temporarily extracted. +-----------------+ [...] org.apache.maven.plugins maven-war-plugin /tmp/extract_here [...] +-----------------+ * <> - set to false to disable the webapp structure cache. Default to true +-----------------+ [...] org.apache.maven.plugins maven-war-plugin false [...] +-----------------+ * Zip dependencies with overlays To use a <> dependency as an overlay you have to configure it explicitely in the plugins's configuration. For instance to inject the content of a zip overlay in the <> directory of the webapp, do as follows: +-----------------+ [...] org.apache.maven.plugins maven-war-plugin zipGroupId zipArtifactId scripts [...] +-----------------+