Ant Build Tool
java ant build tool tutorial
⇒ Ant is a tool for Java application development from Apache which is used for build and deploy of Java applications.
⇒ If we are developing web application or enterprise application, we need to follow few steps to run the application in the server as follow:
- Develop required files(.java, .jsp, .html etc).
- Set the required .jar files into classpath.
- Generate .class files.
- Create required directory structure.
- Generate .war file.
- Start the server.
- Deploy .war file into server.
- Verify functionality of our application based on our project to requirement.
- Sometimes we need to stop server.
- Sometimes we need to un-deploy the application.
⇒ All the above steps are called as Build Process steps for Java application.
⇒ If we are manually follow all the above build process steps then it will increases the project development time and it is also increases the project cost.
⇒ To resolve these problems we need to use any one of build tool.
⇒ If we are using any of the build tool in our application to automate build process steps then it will decreases project development time and project development cost.
⇒ Now we have build tools in the market to automate build process steps for the Java applications, most popular is 1. Ant and 2. Maven
⇒ Ant is a build tool, by using this tool we can automate build process steps for Java applications.
⇒ It is an open source framework which is given by Apache Software Foundation.
⇒ Ant build tool developed by using Java language.
Environment setup for the ANT:
1. Download ANT software (ant…zip file) from Apache website. http://ant.apache.org
2. Extract the zip, and set two system environment variables for example:
Computer->Properties->Advanced system settings->Environment variables->System variable
ANT_HOME=E:apache-ant-1.8.4 [create a new system variable]
PATH=E:apache-ant-1.8.4bin [ edit the “path” system variable and add it by appending ‘;’ into the existing content]
3. To verify whether ANT successfully installed or not, we need to open command prompt and enter below command:
⇒ If we want automate build process steps by using ANT build tool then we need to provide some instructions about our build process steps in the form of XML tags to the ANT build tool and that XML file name should be “build.xml” file and we need to save the “build.xml” file in the project root directory.
⇒ To run build.xml file we need to open command prompt and go to where our build.xml file existed.
⇒ Now to run build.xml file we have 2 ways:
- Executing target by target – To execute target by target we change directory in Command Prompt and execute below command:
C:Userstechnowlogeek>cd E:helloworld [Here “E:helloworld” is my project workspace, we can create it anywhere we want.]
Syntax: E:helloworldant <target name>
Example: E:helloworldant compile
- Executing default target – If we want to execute default target we need to use “default” attribute in <target> tag and we need to use “depends” attribute in all the target tags in “build.xml” file.
⇒ The project directory structure should be as below: