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 - Extending Ant
Ant - Extending Ant
Ant comes with a predefined set of tasks, however you can create your own tasks, as shown in the example below.
Custom Ant Tasks should extend the org.apache.tools.ant.Task class and should extend the execute() method.
Below is a simple example −
package com.tutorialspoint.ant; import org.apache.tools.ant.Task; import org.apache.tools.ant.Project; import org.apache.tools.ant.BuildException; pubpc class MyTask extends Task { String message; pubpc void execute() throws BuildException { log("Message: " + message, Project.MSG_INFO); } pubpc void setMessage(String message) { this.message= message; } }
To execute the custom task, you need to add the following to the Hello World Fax web apppcation −
<target name="custom"> <taskdef name="custom" classname="com.tutorialspoint.ant.MyTask" /> <custom message="Hello World!"/> </target>
Executing the above custom task prints the message Hello World!
c:>ant custom test: [custom] Message : Hello World! elapsed: 0.2 sec BUILD PASSED
This is just a simple example. You can use the power of Ant to do whatever you want to improve your build and deployment process.
Advertisements