[ Team LiB ] |
3.14 Building JAR Files3.14.1 Problem3.14.2 Solution3.14.3 DiscussionThe jar task creates JAR files, as expected. In its simplest form, you specify the name of the new JAR file along with the directory containing files to add to the archive. All files in the directory specified by basedir along with subdirectories and files are added: <jar jarfile="${dir.dist}/oreilly.jar" basedir="${dir.build}"/> The jar task tries to be as efficient as possible. Before creating a new JAR, it checks for an existing archive and compares file timestamps. In our example, oreilly.jar is only created if it does not exist, or if any of the files in ${dir.build} are newer than oreilly.jar. This next example refines our operation by only including .class files, unless they are unit tests matching the Test*.class pattern: <jar jarfile="${dir.dist}/oreilly.jar" basedir="${dir.build}" includes="**/*.class" excludes="**/Test*.class"/> The includes and excludes attributes use the ** pattern to represent any subdirectory. Use nested <fileset> tags for more sophisticated selections: <jar jarfile="${dir.dist}/oreilly.jar"> <fileset dir="${dir.build}" includes="**/*.class" excludes="**/Test*.class"/> <fileset dir="${dir.src}" includes="**/*.properties"/> </jar> This JAR file consists of all .class files (except for Test*.class) in the build directory tree. It also contains all .properties files under the source directory tree.
3.14.4 See AlsoRecipe 3.10 covers Ant's pattern-matching syntax. |
[ Team LiB ] |