Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to call java method from ant task ?

 
mukesh pandey
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20555
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to our build tools forum.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic