Apache ANT Tutorial
Apache ANT Resources
Selected Reading
- ANT - Listeners and Loggers
- ANT - Custom Components
- ANT - Using If Else arguments
- ANT - Using Command Line Arguments
- ANT - Using Token
- ANT - Extending Ant
- ANT - JUnit Integration
- ANT - Eclipse Integration
- ANT - Executing Java code
- ANT - Deploying Applications
- ANT - Packaging Applications
- ANT - Create WAR Files
- ANT - Creating JAR files
- ANT - Build Documentation
- ANT - Building Projects
- ANT - Data Types
- ANT - Property Files
- ANT - Property Task
- ANT - Build Files
- ANT - Environment Setup
- ANT - Introduction
- ANT - Home
Apache ANT Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
ANT - Using Command Line Arguments
Ant - Using Command Line Arguments
Ant can read command pne arguments easily to pass data to its tasks.
Commnd Line Arguments Options
ant [options] [target [target2 [target3] ...]] Options: -help, -h print this message and exit -projecthelp, -p print project help information and exit -version print the version information and exit -diagnostics print information that might be helpful to diagnose or report problems and exit -quiet, -q be extra quiet -silent, -S print nothing but task outputs and build failures -verbose, -v be extra verbose -debug, -d print debugging information -emacs, -e produce logging information without adornments -pb <path> specifies a path to search for jars and classes -logfile <file> use given file for log -l <file> -logger <classname> the class which is to perform logging -pstener <classname> add an instance of class as a project pstener -noinput do not allow interactive input -buildfile <file> use given buildfile -file <file> -f <file> -D <property>=<value> use value for given property -keep-going, -k execute all targets that do not depend on failed target(s) -propertyfile <name> load all properties from file with -D properties taking precedence -inputhandler <class> the class which will handle input requests -find <file> (s)earch for buildfile towards the root of -s <file> the filesystem and use it -nice number A niceness value for the main thread:1 (lowest) to 10 (highest); 5 is the default -nouserpb Run ant without using the jar files from ${user.home}/.ant/pb -noclasspath Run ant without using CLASSPATH -autoproxy Java 5+ : use the OS proxies -main <class> override Ant s normal entry point
We ll be using -Dproperty to pass varibles to the build task.
Example
Create a src folder with text1.txt file with following contents −
This is a sample text written in 2021.
Create build.xml with the following content −
<?xml version="1.0"?> <project name="sample" basedir="." default="copy"> <target name="copy"> <copy todir="${dest.dir}" filtering="true"> <fileset dir="${src.dir}"/> </copy> </target> </project>
Output
Here we re using src.dir and dest.dir properties without defining them. We ll pass them using command pne arguments. Running Ant on the above build file produces the following output −
F: utorialspointant>ant -Dsrc.dir=src -Ddest.dir=build Buildfile: F: utorialspointantuild.xml copy: [copy] Copying 1 file to F: utorialspointantuild BUILD SUCCESSFUL Total time: 0 seconds F: utorialspointant>
Verify the content of copied file to build folder.
This is a sample text written in 2021.Advertisements