Filtering in Maven War Plugin

给你一囗甜甜゛ 提交于 2019-12-23 20:34:24

问题


I don´t understand the following filter configuration for the maven war plugin. Could somebody explain me please, what they are doing? I have marked the code with First Example and Second Example

    <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <webResources>
                    <!--First Example-->
                    <resource>
                        <directory>/src/main/webapp</directory>
                        <filtering>true</filtering>
                        <includes>
                            <include>**/*.xml</include>
                            <include>**/*.xhtml</include>
                        </includes>
                    </resource>
                    <!--Second Example-->  
                    <resource>
                        <directory>${basedir}/src/main/webapp</directory>
                        <filtering>false</filtering>
                        <excludes>
                            <exclude>**/*.xml</exclude>
                            <exclude>**/*.xhtml</exclude>
                        </excludes>
                    </resource>
                </webResources>
            </configuration>
        </plugin>

回答1:


I know this is kind of old question, but the other answer is so misleading that I felt I should clarify it...

Filtering in Maven usually denotes a concept of substituting property placeholders in processed text files (e.g. replacing occurrences of ${project.version} with your project's actual version).

Your configuration can be read as: Every XML and/or XHTML file should undergo property substitution when copied to the target directory, while everything else should be simply copied to the target directory without any processing.

Some further reading:

  • filtering of resources
  • filtering of webapp resources
  • filtering of web.xml



回答2:


Filtering in war plugin configuration is used to include/exclude chosen directories/files. Given configuration is as follows:

<resource>
    <directory>/src/main/webapp</directory>
    <filtering>true</filtering>
    <includes>
         <include>**/*.xml</include>
         <include>**/*.xhtml</include>
    </includes>
</resource>

Filtering configured above is set for /src/main/webapp as root directory There is as flag called filtering which is used to enable/disable filtering

<include>**/*.xml</include>

means that all .xml files within any subdirectory of root directory (/src/main/webapp) will be included. Next include means the same but with .xhtml files

<resource>
   <directory>${basedir}/src/main/webapp</directory>
   <filtering>false</filtering>
   <excludes>
      <exclude>**/*.xml</exclude>
      <exclude>**/*.xhtml</exclude>
   </excludes>
</resource>

All parameters are the same as in previous part except exclude which have opposite meaning to include ${basedir} is used when root directory i located in different path then pom.xml. In above example it's not neccesary

Hope this'll help to understand it



来源:https://stackoverflow.com/questions/25742889/filtering-in-maven-war-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!