GeeCON Prague 2014*
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


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
Author

How to call java method from ant task ?

mukesh pandey
Greenhorn

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;

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

public class MyVeryOwnTask extends Task {
private String msg;

// The method executing the task
public void execute() throws BuildException {
System.out.println(msg);

}

// 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!" />

</target>
</project>

====================================================================

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
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

Moving to our build tools forum.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
GeeCON Prague 2014
 
subject: How to call java method from ant task ?