ANT Tasks – BaseName

Apache Ant Tasks – BaseName ”; Previous Next Description Basename task determines the base name of the specified file/directory while removing the suffix if passed. In case of full path of file, the name of the file is used. In case of directory path, the name of the last directory is used. Properties Sr.No Attributes & Description 1 File The path to take the basename of. (Mandatory) 2 Property The name of the property to set. (Mandatory) 3 Suffix The suffix to remove from the resulting basename (specified either with or without the .). (Optional) Example Usage Create build.xml with the following content − <?xml version=”1.0″?> <project name=”TutorialPoint” default=”info”> <target name=”info”> <basename property=”cmdname” file=”D:/usr/local/application.exe” suffix=”.exe”/> <echo message=”${cmdname}”></echo> </target> </project> Output Running Ant on the above build file produces the following output − F:tutorialspointant>ant Buildfile: F:tutorialspointantbuild.xml info: [echo] application BUILD SUCCESSFUL Total time: 0 seconds Print Page Previous Next Advertisements ”;

ANT Tasks – LoadFile

Apache Ant Tasks – LoadFile ”; Previous Next Description Loadfile task loads a file and sets its content into property. Properties Sr.No Attributes & Description 1 srcFile Source File. 2 Property Property to save to. 3 Encoding Encoding to use when loading the file. 4 failonerror Whether to halt the build on failure. 5 Quiet Do not display a diagnostic message (unless Apache Ant has been invoked with the -verbose or -debug switches) or modify the exit status to reflect an error. Setting this to true implies setting failonerror to false. Usage Create message.txt with the following content − Welcome to tutorialspoint.com Example Create build.xml with the following content − <?xml version=”1.0″?> <project name=”TutorialPoint” default=”info”> <loadfile property=”message” srcFile=”message.txt”/> <target name=”info”> <echo message=”${message}”/> </target> </project> Output Running Ant on the above build file produces the following output − F:tutorialspointant>ant Buildfile: F:tutorialspointantbuild.xml info: [echo] Welcome to tutorialspoint.com BUILD SUCCESSFUL Total time: 0 seconds Print Page Previous Next Advertisements ”;

Ant Tasks – Useful Resources

Apache Ant Tasks – Useful Resources ”; Previous Next The following resources contain additional information on Apache ANT Tasks. Please use them to get more in-depth knowledge on this. Useful Links on Apache ANT Tasks Apache ANT Tasks − Official Website of Apache ANT Tasks. Useful Books on Apache ANT Tasks To enlist your site on this page, please drop an email to [email protected] Print Page Previous Next Advertisements ”;

ANT Tasks – Introduction

Apache Ant Tasks – Introduction ”; Previous Next ANT stands for Another Neat Tool. It is a Java-based build tool from computer software development company Apache. Before going into the details of Apache Ant, let us first understand why we need a build tool. Need for a Build Tool On an average, a developer spends a substantial amount of time doing mundane tasks like build and deployment that include − Compiling the code Packaging the binaries Deploying the binaries to the test server Testing the changes Copying the code from one location to another To automate and simplify the above tasks, Apache Ant is useful. It is an Operating System build and deployment tool that can be executed from the command line. Ant tasks simplifies executions of operations. History of Apache Ant Ant was created by software developer James Duncan Davidson who is also the original creator of webserver application Tomcat. Ant was originally used to build Tomcat, and was bundled as a part of Tomcat distribution. It was born out of the problems and complexities associated with the Apache Make tool. It was promoted as an independent project in Apache in the year 2000. The latest version of Apache Ant as on October 2021 is 1.10.12. Features of Apache Ant The features of Apache Ant are listed below − It is the most complete Java build and deployment tool available. It is platform neutral and can handle platform specific properties, such as file separators. It can be used to perform platform specific tasks such as modifying the modified time of a file using ”touch” command. Ant scripts are written using plain XML. If you are already familiar with XML, you can learn Ant pretty quickly. Ant is good at automating complicated repetitive tasks. Ant comes with a big list of predefined tasks. Ant provides an interface to develop custom tasks. Ant can be easily invoked from the command line and it can integrate with free and commercial IDEs. Print Page Previous Next Advertisements ”;

ANT Tasks – Copy

Apache Ant Tasks – Copy ”; Previous Next Description Copy task copies a file/resource collection to a new file or directory. Files are only copied if the source file is newer than the destination file, or when the destination file does not exist. Properties Sr.No Attributes & Description 1 File The file to copy. (Mandatory) 2 Preservelastmodified Give the copied files the same last modified time as the original source files. 3 Tofile The file to copy to. 4 Todir The directory to copy to. 5 Overwrite Overwrite existing files even if the destination files are newer. 6 Force Overwrite read-only destination files. 7 Filtering Indicates whether token filtering using the global build-file filters should take place during the copy. 8 Flatten Ignore the directory structure of the source files, and copy all files into the directory specified by the todir attribute. 9 includeEmptyDirs Copy any empty directories included in the FileSet(s). 10 Failonerror If false, log a warning message, but do not stop the build, when the file to copy does not exist or one of the nested filesets points to a directory that doesn”t exist or an error occurs while copying. 11 Quiet If true and failonerror is false, then do not log a warning message when the file to copy does not exist or one of the nested filesets points to a directory that doesn”t exist or an error occurs while copying. 12 Verbose Log the files that are being copied. 13 Encoding The encoding to assume when filter-copying the files. 14 Outputencoding The encoding to use when writing the files. 15 Enablemultiplemappings If true the task will process to all the mappings for a given source path. If false the task will only process the first file or directory. This attribute is only relevant if there is a mapper subelement. 16 Granularity The number of milliseconds leeway to give before deciding a file is out of date. This is needed because not every file system supports tracking the last modified time to the millisecond level. This can also be useful if source and target files live on separate machines with clocks being out of sync. Example Usage Create build.xml with the following content − <?xml version=”1.0″?> <project name=”TutorialPoint” default=”info”> <target name=”info”> <copy file=”text.txt” tofile=”textcopy.txt”></copy> </target> </project> Above script will copy a file say text.txt in the current directory as textcopy.txt. Output Running Ant on the above build file produces the following output − F:tutorialspointant>ant Buildfile: F:tutorialspointantbuild.xml info: [echo] Copying 1 file to F:tutorialspointant BUILD SUCCESSFUL Total time: 1 second Print Page Previous Next Advertisements ”;

ANT Tasks – Condition

Apache Ant Tasks – Condition ”; Previous Next Description Condition task sets the property value to true by default if condition is true; otherwise, the property is not set. You can set the value to something other than the default by specifying the value attribute. Properties Sr.No Attributes & Description 1 Property The name of the property to set. (Mandatory) 2 Value The value to set the property to. 3 Else The value to set the property to if the condition evaluates to false. Example Usage Create build.xml with the following content − <?xml version=”1.0″?> <project name=”TutorialPoint” default=”info”> <condition property=”isWindows”> <os family=”windows”/> </condition> <target name=”info”> <echo message=”${isWindows}”></echo> </target> </project> Above script will set a variable is Windows based on the underlying operation system is windows or not. Output Running Ant on the above build file produces the following output − F:tutorialspointant>ant Buildfile: F:tutorialspointantbuild.xml info: [echo] true BUILD SUCCESSFUL Total time: 0 seconds Print Page Previous Next Advertisements ”;