Tutorials Navigation

Tutorials: 15,039 Categories: 40
Total Tutorial Views: 28,935,805

Apache Ant Tutorial - Extending Ant

Tutorial Name: Apache Ant Tutorial - Extending Ant  

Category: PC Miscellaneous

Submitted By: Mooneye

Date Added:

Comments: 0

Views: 109

Share:


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.example.ant;

import org.apache.tools.ant.Task;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.BuildException;

public class MyTask extends Task {
String message;

public void execute() throws BuildException {
log("Message: " + message, Project.MSG_INFO);
}

public void setMessage(String message) {
this.message = message;
}
}


To execute the custom task, you need to add the following to the Hello World Fax web application

<target name = "custom">
<taskdef name = "custom" classname = "com.example.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.

Ratings

Please take one second and rate this tutorial...

Not a Chance
1
2
3
4
5
6
7
8
9
10
Absolutely

Comments

"Apache Ant Tutorial - Extending Ant" :: Login/Create an Account :: 0 comments

If you would like to post a comment please signin to your account or register for an account.