DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report

My Latest Refcard: Apache Ant

James Sugrue user avatar by
James Sugrue
CORE ·
Jun. 28, 10 · Interview
Like (1)
Save
Tweet
Share
10.01K Views

Join the DZone community and get the full member experience.

Join For Free

Today DZone are launching my latest refcard where I cover Apache Ant. The purpose of the card is to be a pure reference for the tasks available. This was an interesting refcard to write as I have been using Ant for so long, that I took the range of functions that it can perform for granted. While I'm sure a lot of you have moved on from Ant, it's still a widely used technology in a lot of software development organisations. It's present in all Java IDEs, and I still use it in my day job.

There are a few things that I didn't have the space in the card to elaborate on. One was examples for each of the tasks, which I will provide in a later example. The second was to show how to create your own tasks for us in Ant.

When it comes to creating your own tasks, it couldn't be easier. To create your own task you just need to extend org.apache.tools.ant.Task. There are also a number of other base classes that you can extend such as JDBCTask or MatchingTask. Every attribute in your task will need to have a corresponding setter method in the Task. And finally, for execution of the task you'll need to put the implementation in the public void execute() method, which throw a BuildException in case anything goes wrong.
Here's a short example of a task implementation:

package com.dzone.ant.tasks;

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

public class CustomTask extends Task
{
private String attribute1;
private boolean attribute2;

public void setAttribute1(String s)
{
attribute1 = s;
}
public void setAttribute2(boolean b)
{
attribute2 = b;
}

public void execute() throws BuildException
{
//task logic here
}
}

To use the task in your Ant script, you'll need to create a taskdef to point to it.

<taskdef name="dzonetask" classname="com.dzone.ant.tasks.CustomTask"/>

And you can now use the task later on in your xml, using the value of the name attribute for the task:

<dzonetask attribute1="attvalue" attribute2="true"/>

Finally, if you want to provide your task as if it was one of the default tasks in Ant, you can add the task to the default.properties file in org.apache.tools.ant.taskdefs package.

I hope you find that this card is useful to you. As always, any feedback is welcome, so that we can ensure the refcard is as helpful as possible.

 
Task (computing) Apache Ant

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • 10 Things to Know When Using SHACL With GraphDB
  • Beyond Coding: The 5 Must-Have Skills to Have If You Want to Become a Senior Programmer
  • 19 Most Common OpenSSL Commands for 2023
  • Using Swagger for Creating a PingFederate Admin API Java Wrapper

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: