当前位置:网站首页>Apache ant extension tutorial
Apache ant extension tutorial
2022-07-03 15:05:00 【trium_ KW】
Apache Ant We are committed to becoming a flexible and convenient construction tool , Though right Java Support more , Some third-party libraries can also be used to support the construction of other languages , Even some routine maintenance tasks . Whereas Apache Ant Use XML As a configuration language , Be good at description , And cannot deal with overly complex process logic , So there is the famous Ant-Contrib Expansion pack, ( Home page see here ) Where it comes in handy .Ant-Contrib Of course, the use of has increased Apache Ant The programmability of , But from the author's point of view , Contrary to Apache Ant Design intention of , meanwhile XML Even if it has programming ability , The logical expressiveness of traditional programming languages is by no means XML Comparable . in fact , Through its official API Expand Apache Ant Make it complete the user customization function , In the long run , It has better simplicity 、 Robustness, 、 Maintainability and stability , It's just relatively friendly XML, read API The arduous task of concealing expansion Apache Ant Just the advantage of .
Apache Ant The build file consists of two elements , Namely Task
( Mission ) and DataType
( data type ). generally , Type represents a collection of resources , Such as Fileset
( File set ); Tasks are used to perform certain operations . Although there are many differences between tasks and types , But both from Java There are many similarities in class structure . for example :
package packagePath;
import org.apache.tools.ant.Task; // Tasks are inherited from here
import org.apache.tools.ant.BuildException;
/* * Use Java Bean Specification definition XML attribute , Attribute name from getter/setter Guess from the name . * To add child elements , Need to use addXXX(YYYY e) Method .XXX For the child element XML Element name * ( stay XML Regardless of case , But in Java The naming in should conform to Java Bean standard ); * YYYY For its practical Java Class name . */
public class MyTask extends Task {
private String myStringAttribute;
private int myIntAttribute;
private File myFileAttribute;
private ArrayList<SelfDefinedSubElement> l;
public MyTask() {
l = new ArrayList<SelfDefinedSubElement>();
}
public String getMyStringAttribute() {
return myStringAttribute;
}
// The other two getters ...
public void setMyStringAttribute(String myStringAttribute) {
this.myStringAttribute = myStringAttribute;
}
// The other two setters ...
public void addSelfDefinedElement(SelfDefinedSubElement e) {
l.add(e);
}
/* * Start the task here .DataType There is no such method ; but DataType Get references * Methods , That is, use attributes in one place id Mark the data type and then use it in another place refid * Get its reference . Detailed inquiry Apache Ant API */
@Override
public void execute() {
if (myStringAttribute == null) {
throw new BuildException("myStringAttribute not set");
}
// Other input checks ...
// What to do ...
}
}
This is a task , One Java
file .
# Defined here MyTask stay XML Element name in
nameUsedByMyTaskInBuildfile=packagePath.MyTask
selfDefinedElement= Its fully qualified classpath
This is the mission statement , One propertes
file .
<target name="XXX">
<!-- some other tasks -->
<nameUsedByMyTaskInBuildfile myStringAttribute="stringValue" myFileAttribute="C:\Users" myIntAttribute="5">
<selfDefinedElement someAttributes="" />
</nameUsedByMyTaskInBuildfile>
<!-- some other tasks -->
</target>
This is a possible corresponding to the task XML Example .
package anotherPackagePath;
import org.apache.tools.ant.types.DataType; // The data type inherits from here
import org.apache.tools.ant.BuildException;
/* * The description is the same as the task description */
public class MyType extends DataType {
private String myStringAttribute;
private int myIntAttribute;
private File myFileAttribute;
private ArrayList<AnotherSelfDefinedSubElement> l;
public MyTask() {
l = new ArrayList<AnotherSelfDefinedSubElement>();
}
public String getMyStringAttribute() {
return myStringAttribute;
}
// The other two getters ...
public void setMyStringAttribute(String myStringAttribute) {
this.myStringAttribute = myStringAttribute;
}
// The other two setters ...
public void addAnotherSelfDefinedElement(AnotherSelfDefinedSubElement e) {
l.add(e);
}
}
This is a data type , One Java
file .
nameUsedByMyTypeInBuildfile=anotherPackagePath.MyType
anotherSelfDefinedElement= Its fully qualified classpath
This is the data type declaration , One propertes
file .
<nameUsedByMyTypeInBuildfile myStringAttribute="stringValue" myFileAttribute="C:\Users" myIntAttribute="5" id="my.id">
<anotherSelfDefinedElement someAttributes="" />
</nameUsedByMyTypeInBuildfile>
This is a possible corresponding to this data type XML Example .
- Related reading :
- Apache Ant API The basic use method
- Apache Ant API( This is a download address ,Apache Ant No official online API)
边栏推荐
- How can entrepreneurial teams implement agile testing to improve quality and efficiency? Voice network developer entrepreneurship lecture Vol.03
- Class part2
- 4-29——4.32
- Simulation of LS -al command in C language
- 链表有环,快慢指针走3步可以吗
- 【pytorch学习笔记】Transforms
- 基础SQL教程
- Awvs batch operation script
- Implement Gobang with C language
- Global and Chinese market of marketing automation 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢
[graphics] efficient target deformation animation based on OpenGL es 3.0
Tencent internship interview sorting
[ue4] HISM large scale vegetation rendering solution
远程服务器后台挂起 nohup
[transform] [practice] use pytoch's torch nn. Multiheadattention to realize self attention
Open under vs2019 UI file QT designer flash back problem
On MEM series functions of C language
【Transform】【NLP】首次提出Transformer,Google Brain团队2017年论文《Attention is all you need》
Troubleshooting method of CPU surge
Talking about part of data storage in C language
随机推荐
2021-10-16 initial programming
[ue4] geometry drawing pipeline
Global and Chinese markets for transparent OLED displays 2022-2028: Research Report on technology, participants, trends, market size and share
Yolov5 advanced seven target tracking latest environment construction (II)
Yolov5进阶之八 高低版本格式转换问题
[Yu Yue education] scientific computing and MATLAB language reference materials of Central South University
Yolov5 advanced nine target tracking example 1
【Transform】【NLP】首次提出Transformer,Google Brain团队2017年论文《Attention is all you need》
[graphics] adaptive shadow map
Zzuli:1059 highest score
Open under vs2019 UI file QT designer flash back problem
What is embedding (encoding an object into a low dimensional dense vector), NN in pytorch Principle and application of embedding
NOI OPENJUDGE 1.4(15)
Finally, someone explained the financial risk management clearly
406. Reconstruct the queue according to height
Several sentences extracted from the book "leather bag"
Vs+qt multithreading implementation -- run and movetothread
[engine development] rendering architecture and advanced graphics programming
Byte practice plane longitude 2
第04章_逻辑架构