[Apache --- Ant]DIY Ant Task I --- The Simplest one
2007-01-11 16:33
239 查看
build.xml:
<project name="AntTest" default="main" basedir=".">
<property name="classpath" value="${basedir}/bin"/>
<target name="init"/>
<target name="simpletask" depends="init">
<taskdef name="simpletask" classname="org.xxx.anttest.SimpleTask" classpath="${classpath}"/>
<simpletask />
</target>
<target name="main" depends="simpletask" />
</project>
Source:
package org.xxx.anttest;
public class SimpleTask {
public void execute(){
System.out.println("This is a DIY ant task!!");
}
}
Task lifecycle
There are different stages in the processing of a build file, and the objects that implement tasks are used throughout the stages.
Here is the lifecycle of Ant tasks. The build begins with Ant loading and parsing the
build file.
1 As Ant parses the build file, it creates an instance of the appropriate subclass of
Task for every declaration of a task in the file, using its empty constructor.
2 Ant then informs the task about its containing project, target, and some other
minor details, such as which line of the build file contains it.
3 Ant calls the init()method of the Task class. Most tasks do not override this.
4 Ant proceeds to execute the targets in the order it determines is appropriate,
conceivably not executing all of them, depending upon whether conditional
targets have their conditions met.
5 The tasks inside a target are executed one by one, For each task, Ant configures
it with the attribute and element values in the build file, then calls its execute()
method
This does not quite explain how a class that does not extend org.apache.tools.
ant.Task works. The answer is that there is a TaskAdapter in Ant’s API that does
extend from Task, and contains an instance of the Object, and invokes its execute
method. The TaskAdapter is used internally to Ant for tasks that do not
extend from Task.
<project name="AntTest" default="main" basedir=".">
<property name="classpath" value="${basedir}/bin"/>
<target name="init"/>
<target name="simpletask" depends="init">
<taskdef name="simpletask" classname="org.xxx.anttest.SimpleTask" classpath="${classpath}"/>
<simpletask />
</target>
<target name="main" depends="simpletask" />
</project>
Source:
package org.xxx.anttest;
public class SimpleTask {
public void execute(){
System.out.println("This is a DIY ant task!!");
}
}
Task lifecycle
There are different stages in the processing of a build file, and the objects that implement tasks are used throughout the stages.
Here is the lifecycle of Ant tasks. The build begins with Ant loading and parsing the
build file.
1 As Ant parses the build file, it creates an instance of the appropriate subclass of
Task for every declaration of a task in the file, using its empty constructor.
2 Ant then informs the task about its containing project, target, and some other
minor details, such as which line of the build file contains it.
3 Ant calls the init()method of the Task class. Most tasks do not override this.
4 Ant proceeds to execute the targets in the order it determines is appropriate,
conceivably not executing all of them, depending upon whether conditional
targets have their conditions met.
5 The tasks inside a target are executed one by one, For each task, Ant configures
it with the attribute and element values in the build file, then calls its execute()
method
This does not quite explain how a class that does not extend org.apache.tools.
ant.Task works. The answer is that there is a TaskAdapter in Ant’s API that does
extend from Task, and contains an instance of the Object, and invokes its execute
method. The TaskAdapter is used internally to Ant for tasks that do not
extend from Task.
相关文章推荐
- [Apache --- Ant]DIY Ant Task II --- a little more difficult
- The type org.apache.tools.ant.Task cannot be resolved. It is indirectly referenced from required .cl
- 【ANT】taskdef class org.programmerplanet.ant.taskdefs.jmeter.JMeterTask cannot be found using the cla
- taskdef class org.apache.catalina.ant.InstallTask cannot be found!
- Apache Cordova vs Adobe PhoneGap: the differences and which one to use
- svnant的BUILD FAILED Problem: failed to create task or type svnSetting Cause: The name is undefined原因
- org.apache.catalina.ant.DeployTask Not Found
- org.apache.tools.ant.taskdefs.optional.junit.JUnitTask was not found解决方法
- 使用one-jar-ant-task快速使现有工程支持jar in jar
- taskdef class com.android.ant.SetupTask cannot be found using the classloader AntClassLoader
- org.apache.tools.ant.taskdefs.Zip使用
- 小程序 表单 formId 为 the formId is a mock one
- 解决编译apache出现的问题:configure: error: APR not found . Please read the documentation
- poj1034 The dog task 最大匹配
- No unnamed transitions were found for the task'' ?????
- HDU-4238-You Are the One (区间DP)
- Project has no default.properties file! Edit the project properties to set one.错误解决方案
- iOS开发 xib错误 One" nib but the view outlet was not set
- The import org.apache.commons cannot be resolved 的报错
- ant中使用java task,classpathref不起作用