File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Ant, Maven and Other Build Tools and the fly likes How to call java method from ant task ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "How to call java method from ant task ?" Watch "How to call java method from ant task ?" New topic

How to call java method from ant task ?

mukesh pandey

Joined: Apr 02, 2010
Posts: 22
Hi, I want to call a java method from ant task I have to pass three argument to that method, though I am able to call a method with single argument but I don't know how to pass three arguments bewlo is the java file and ant file that I made and able to run method with one argument from ant.

java file:
package com.mydomain;


public class MyVeryOwnTask extends Task {
private String msg;

// The method executing the task
public void execute() throws BuildException {


// The setter for the "message" attribute
public void setMessage(String msg) {
this.msg = msg;


and it's ant file

<?xml version="1.0"?>

<project name="Build-example" default="main" basedir=".">
<taskdef name="mytask" classname="com.mydomain.MyVeryOwnTask" classpath="bin" />

<target name="main">
<mytask message="Hello World! MyVeryOwnTask works!" />



here I am passing only one argument but I need to pass multiple argument how can I do that please help.
Ed Ward
Ranch Hand

Joined: Jan 30, 2006
Posts: 147
Just add another attribute in your class as the example you worked from has:

Ant Dev Manual

Add a another private variable, setter for it and println statement for it then add it to your task call.

Rob Spoor

Joined: Oct 27, 2005
Posts: 20184

Moving to our build tools forum.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: How to call java method from ant task ?
It's not a secret anymore!