Ant 简明教程
Ant - Extending Ant
Ant 附带一组预定义的任务,但是您可以创建自己的任务,如下例所示:
Ant comes with a predefined set of tasks, however you can create your own tasks, as shown in the example below.
自定义 Ant 任务应扩展 org.apache.tools.ant.Task 类并且应扩展 execute() 方法。
Custom Ant Tasks should extend the org.apache.tools.ant.Task class and should extend the execute() method.
以下是一个简单的示例 −
Below is a simple example −
package com.tutorialspoint.ant;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.BuildException;
public class MyTask extends Task {
String message;
public void execute() throws BuildException {
log("Message: " + message, Project.MSG_INFO);
}
public void setMessage(String message) {
this.message= message;
}
}
如欲执行自定义任务,您需要将以下内容添加到 Hello World 传真 Web 应用程序 −
To execute the custom task, you need to add the following to the Hello World Fax web application −
<target name="custom">
<taskdef name="custom" classname="com.tutorialspoint.ant.MyTask" />
<custom message="Hello World!"/>
</target>
执行上述自定义任务将打印消息“Hello World!”
Executing the above custom task prints the message 'Hello World!'
c:\>ant custom
test:
[custom] Message : Hello World!
elapsed: 0.2 sec
BUILD PASSED
这仅是一个简单的示例。Ant 允许充分发挥其性能,助您提升构建和部署流程。
This is just a simple example. You can use the power of Ant to do whatever you want to improve your build and deployment process.