Maven WAR overlay

Overlays are used to share common resources across multiple web applications.

 
1.自己项目结构
    |-- 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
2.自己项目需要依赖的项目war
   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
3.在自己项目中添加项目依赖 
<dependencies>
    <dependency>
      <groupId>com.example.projects</groupId>
      <artifactId>documentedprojectdependency</artifactId>
      <version>1.0-SNAPSHOT</version>
      <type>war</type>
      <scope>runtime</scope>
    </dependency>
    ...
  </dependencies>
4.添加依赖后项目可能如下:
-- META-INF
 |   |-- MANIFEST.MF
 |   `-- maven
 |       `-- com.example.projects
 |           `-- documentedproject
 |               |-- 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
期中web.xml 来源于自己项目
 
5.配置overlays
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.6</version>
        <configuration>
          <overlays>
            <overlay>
              <groupId>com.example.projects</groupId>
              <artifactId>documentedprojectdependency</artifactId>
              <excludes>
                <exclude>WEB-INF/classes/images/sampleimage-dependency.jpg</exclude>
              </excludes>
            </overlay>
          </overlays>
        </configuration>
      </plugin>
    </plugins>
  </build>
其中:

The <overlay> element can have the following child elements:

  • id - the id of the overlay. If none is provided, the WAR Plugin will generate one.
  • groupId - the groupId of the overlay artifact you want to configure.
  • artifactId - the artifactId of the overlay artifact you want to configure.
  • type - the type of the overlay artifact you want to configure. Default value is: war.
  • classifier - the classifier of the overlay artifact you want to configure if multiple artifacts matches the groupId/artifactId.
  • includes - the files to include. By default, all files are included.
  • excludes - the files to exclude. By default, the META-INF directory is excluded.
  • targetPath - the target relative path in the webapp structure, which is only available for overlays of type war. By default, the content of the overlay is added in the root structure of the webapp.
  • skip - set to true to skip this overlay. Default value is: false.
  • filtered - whether to apply filtering to this overlay. Default value is false.
     
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
posted @ 2016-04-12 08:53  nicholaswei  阅读(1930)  评论(1编辑  收藏  举报