问题
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