指定资源目录时,可能不会使用该目录中的每个文件。因此,我们可能只需要指定我们想要包含的文件或指定我们想要排除的文件。
要包含一个资源,我们只需要添加一个<includes>元素。
<project> ... <name>My Resources Plugin Practice Project</name> ... <build> ... <resources> <resource> <directory>[your directory]</directory> <includes> <include>[resource file #1]</include> <include>[resource file #2]</include> <include>[resource file #3]</include> ... <include>[resource file #n]</include> </includes> </resource> ... </resources> ... </build> ... </project>
而要排除资源,我们只需要添加一个<excludes>元素。
<project> ... <name>My Resources Plugin Practice Project</name> ... <build> ... <resources> <resource> <directory>[your directory]</directory> <excludes> <exclude>[non-resource file #1]</exclude> <exclude>[non-resource file #2]</exclude> <exclude>[non-resource file #3]</exclude> ... <exclude>[non-resource file #n]</exclude> </excludes> </resource> ... </resources> ... </build> ... </project>
例如,如果我们想在src/my-resources目录及其所有子目录中包含所有文本和 RTF 文件,我们可以执行以下操作:
<project> ... <name>My Resources Plugin Practice Project</name> ... <build> ... <resources> <resource> <directory>src/my-resources</directory> <includes> <include>**/*.txt</include> <include>**/*.rtf</include> </includes> </resource> ... </resources> ... </build> ... </project>
此外,如果我们想要包含除位图、jpeg 和 gif 之外的所有内容,我们可以通过以下方式简单地排除它们:
<project> ... <name>My Resources Plugin Practice Project</name> ... <build> ... <resources> <resource> <directory>src/my-resources</directory> <excludes> <exclude>**/*.bmp</exclude> <exclude>**/*.jpg</exclude> <exclude>**/*.jpeg</exclude> <exclude>**/*.gif</exclude> </excludes> </resource> ... </resources> ... </build> ... </project>
当然,我们也可以同时拥有<includes>和<excludes>元素。例如,如果我们想要包含文件名中不包含“test”一词的所有文本文件。
<project> ... <name>My Resources Plugin Practice Project</name> ... <build> ... <resources> <resource> <directory>src/my-resources</directory> <includes> <include>**/*.txt</include> </includes> <excludes> <exclude>**/*test*.*</exclude> </excludes> </resource> ... </resources> ... </build> ... </project>