编写自定义任务,轻松扩展Ant (3) 代码

类别:Java 点击:0 评论:0 推荐:

FooTask.java:

 

/*

 * Created on 2004-4-17

 *

 */

 

import org.apache.tools.ant.Task;

 

 

/**

 * FooTask.java

 * <p>Copyright: Copyright (c) 2003 你可以对本程序随意修改,复制,使用,但请保留这里注释声明!!!</p>

  * @author 李尚强 [email protected]

 */

 

public class FooTask extends Task {

private String name = "";

/**

 * @return

 */

public String getName() {

    return name;

}

 

/**

 * @param string

 */

public void setName(String string) {

    name = string;

}

public String toString() {

    return name;

}

 

}

 

build.xml:

<?xml version="1.0" ?>

<project name="testTimer" default="test" basedir=".">

<taskdef name="timer" classname="TimerTask" classpath="."/>

<taskdef name="foo" classname="FooTask" classpath="."/>

 

<target name="test">

    <timer action="init">

        <foo name="F1" />

        <foo name="F2" />

        <foo name="F3" />

        <foo name="F4" />                            

    </timer>

   

    <!-- You can do some long-time work here -->

   

    <timer action="print" />

    <echo message="You have use time :${timer.passed}" />

</target>

</project>

本文地址:http://com.8s8s.com/it/it16562.htm