The classpath can be specified via a nested <classpath>, as well - that is, a path-like structure.
The built-in mapper types are:
Examples:
<mapper type="identity"/>
Source file name | Target file name |
A.java | A.java |
foo/bar/B.java | foo/bar/B.java |
C.properties | C.properties |
Classes/dir/dir2/A.properties | Classes/dir/dir2/A.properties |
Examples:
<mapper type="flatten"/>
Source file name | Target file name |
A.java | A.java |
foo/bar/B.java | B.java |
C.properties | C.properties |
Classes/dir/dir2/A.properties | A.properties |
Examples:
<mapper type="merge" to="archive.tar"/>
Source file name | Target file name |
A.java | archive.tar |
foo/bar/B.java | archive.tar |
C.properties | archive.tar |
Classes/dir/dir2/A.properties | archive.tar |
Examples:
<mapper type="glob" from="*.java" to="*.java.bak"/>
Source file name | Target file name |
A.java | A.java.bak |
foo/bar/B.java | foo/bar/B.java.bak |
C.properties | ignored |
Classes/dir/dir2/A.properties | ignored |
<mapper type="glob" from="C*ies" to="Q*y"/>
Source file name | Target file name |
A.java | ignored |
foo/bar/B.java | ignored |
C.properties | Q.property |
Classes/dir/dir2/A.properties | Qlasses/dir/dir2/A.property |
Note that you need to escape a dollar-sign ($) with another dollar-sign in Ant.
The regexp mapper needs a supporting library and an implementation of org.apache.tools.ant.util.regexp.RegexpMatcher that hides the specifics of the library. Ant comes with implementations for the java.util.regex package of JDK 1.4, jakarta-regexp and jakarta-ORO. If you compile from sources and plan to use one of them, make sure the libraries are in your CLASSPATH. For information about using gnu.regexp or gnu.rex with Ant, see this article.
This means, you need optional.jar from the Ant release you are using and one of the supported regular expression libraries. Make sure, both will be loaded from the same classpath, that is either put them into your CLASSPATH, ANT_HOME/lib directory or a nested <classpath> element of the mapper - you cannot have optional.jar in ANT_HOME/lib and the library in a nested <classpath>.
Ant will choose the regular-expression library based on the following algorithm:
If the system property ant.regexp.matcherimpl has been set, it is taken as the name of the class implementing org.apache.tools.ant.util.regexp.RegexpMatcher that should be used.
If it has not been set, first try the JDK 1.4 classes, then jakarta-ORO and finally try jakarta-regexp.
Examples:
<mapper type="regexp" from="^(.*)\.java$$" to="\1.java.bak"/>
Source file name | Target file name |
A.java A. | java.bak |
foo/bar/B.java | foo/bar/B.java.bak |
C.properties | ignored |
Classes/dir/dir2/A.properties | ignored |
<mapper type="regexp" from="^(.*)/([^/]+)/([^/]*)$$" to="\1/\2/\2-\3"/>
Source file name | Target file name |
A.java | ignored |
foo/bar/B.java | foo/bar/bar-B.java |
C.properties | ignored |
Classes/dir/dir2/A.properties | Classes/dir/dir2/dir2-A.properties |
<mapper type="regexp" from="^(.*)\.(.*)$$" to="\2.\1"/>
Source file name | Target file name |
A.java | java.A |
foo/bar/B.java | java.foo/bar/B |
C.properties | properties.C |
Classes/dir/dir2/A.properties | properties.Classes/dir/dir2/A |
package
Sharing the same syntax as the glob mapper, the package mapper
replaces directory separators found in the matched source pattern with
dots in the target pattern placeholder. This mapper is particularly
useful in combination with <uptodate> and <junit> output.
Example:
<mapper type="package" from="*Test.java" to="TEST-*Test.xml"/>
Source file name Target file name
org/apache/tools/ant/util/PackageMapperTest.java TEST-org.apache.tools.ant.util.PackageMapperTest.xml
org/apache/tools/ant/util/Helper.java ignored