Patterns look very much like the patterns used in DOS and UNIX:
"
*
" matches zero or more characters, "?
" matches one character.In general, patterns are considered relative paths, relative to a task dependent base directory (the
dir
attribute in the case of<fileset>
). Only files found below that base directory are considered. So while a pattern like../foo.java
is possible, it will not match anything when applied since the base directory's parent is never scanned for files.Examples
*.java
matches.java
,x.java
andFooBar.java
, but not(does not end withFooBar.xml
.java
).?.java
matchesx.java
,A.java
, but notor.java
(both don't have one character beforexyz.java
.java
).Combinations of "
*
"'s and "?
"'s are allowed.Matching is done per-directory. This means that first the first directory in the pattern is matched against the first directory in the path to match. Then the second directory is matched, and so on. For example, when we have the pattern
/?abc/*/*.java
and the path/xabc/foobar/test.java
, the first?abc
is matched withxabc
, then*
is matched withfoobar
, and finally*.java
is matched withtest.java
. They all match, so the path matches the pattern.To make things a bit more flexible, we add one extra feature, which makes it possible to match multiple directory levels. This can be used to match a complete directory tree, or a file anywhere in the directory tree. To do this, "
**
" must be used as the name of a directory. When**
is used as the name of a directory in the pattern, it matches zero or more directories. For example:/test/**
matches all files/directories under/test/
, such as/test/x.java
, or/test/foo/bar/xyz.html
, but not./xyz.xml
There is one "shorthand": if a pattern ends with "
/
" or "\
", then "**
" is appended. For example,mypackage/test/
is interpreted as if it weremypackage/test/**
.Example Patterns
**/CVS/*
Matches all files inCVS
directories that can be located anywhere in the directory tree.
- ✅
CVS/Repository
- ✅
org/apache/CVS/Entries
- ✅
org/apache/jakarta/tools/ant/CVS/Entries
- ❌
org/apache/CVS/foo/bar/Entries
(part does not match)foo/bar/
org/apache/jakarta/**
Matches all files in theorg/apache/jakarta
directory tree.
- ✅
org/apache/jakarta/tools/ant/docs/index.html
- ✅
org/apache/jakarta/test.xml
- ❌
org/apache/xyz.java
(part is missing)jakarta/
org/apache/**/CVS/*
Matches all files inCVS
directories that are located anywhere in the directory tree underorg/apache
.
- ✅
org/apache/CVS/Entries
- ✅
org/apache/jakarta/tools/ant/CVS/Entries
- ❌
org/apache/CVS/foo/bar/Entries
(part does not match)foo/bar/
**/test/**
Matches all files that have atest
element in their path, includingtest
as a filename.When these patterns are used in inclusion and exclusion, you have a powerful way to select just the files you want.
The mapping matches URLs using the following rules:
?
matches one character*
matches zero or more characters**
matches zero or more directories in a path{spring:[a-z]+}
matches the regexp[a-z]+
as a path variable named "spring
"Examples
com/t?st.jsp
— matchescom/test.jsp
but alsocom/tast.jsp
orcom/txst.jsp
com/*.jsp
— matches all.jsp
files in thecom
directorycom/**/test.jsp
— matches alltest.jsp
files underneath the com pathorg/springframework/**/*.jsp
— matches all.jsp
files underneath theorg/springframework
pathorg/**/servlet/bla.jsp
— matchesorg/springframework/servlet/bla.jsp
but alsoorg/springframework/testing/servlet/bla.jsp
andorg/servlet/bla.jsp
com/{filename:\\w+}.jsp
will matchcom/test.jsp
and assign the value test to thefilename
variable