假设我有这个ant任务,它接受一个字符串并打印出来。
public class MyTask extends Task
{
private String msg;
// method executing the task
public void execute() throws BuildException
{
System.out.println(msg);
}
public void setMessage (String msg)
{
this.msg = msg;
}
}
我应该如何编写构建文件以将字符串参数传递给它?
(说我喜欢做ant mytask -Dmessage=print_this_message
)
由于
答案 0 :(得分:1)
您需要在构建文件中声明任务并将属性值作为属性传递
<taskdef ....
<mytask message="${message}"/>
要在任务的字符串上设置默认值,只需初始化消息私有变量
public class MyTask extends Task
{
private String msg = "hello world";
public void execute() throws BuildException
{
System.out.println(msg);
}
public void setMessage (String msg)
{
this.msg = msg;
}
}