当前位置:网站首页>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)
边栏推荐
- [engine development] rendering architecture and advanced graphics programming
- 解决pushgateway数据多次推送会覆盖的问题
- Finally, someone explained the financial risk management clearly
- [ue4] geometry drawing pipeline
- 【Transform】【NLP】首次提出Transformer,Google Brain团队2017年论文《Attention is all you need》
- PHP GD image upload bypass
- mmdetection 学习率与batch_size关系
- [opengl] bone animation blending effect
- Mmdetection learning rate and batch_ Size relationship
- How can entrepreneurial teams implement agile testing to improve quality and efficiency? Voice network developer entrepreneurship lecture Vol.03
猜你喜欢

4-20-4-23 concurrent server, TCP state transition;

【注意力机制】【首篇ViT】DETR,End-to-End Object Detection with Transformers网络的主要组成是CNN和Transformer

cpu飙升排查方法

Yolov5系列(一)——網絡可視化工具netron

Talking about part of data storage in C language

Série yolov5 (i) - - netron, un outil de visualisation de réseau

4-29——4.32

5-1 blocking / non blocking, synchronous / asynchronous

Rasterization: a practical implementation (2)

第04章_逻辑架构
随机推荐
App global exception capture
[pytorch learning notes] datasets and dataloaders
Yolov5进阶之七目标追踪最新环境搭建(二)
Global and Chinese market of transfer case 2022-2028: Research Report on technology, participants, trends, market size and share
PS tips - draw green earth with a brush
Joomla! CMS 3.0~3.4.6 RCE
406. Reconstruct the queue according to height
[graphics] adaptive shadow map
[transform] [practice] use pytoch's torch nn. Multiheadattention to realize self attention
B2020 points candy
使用Tengine解决负载均衡的Session问题
Global and Chinese market of iron free motors 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese markets for ionization equipment 2022-2028: Research Report on technology, participants, trends, market size and share
Yolov5系列(一)——網絡可視化工具netron
Zero copy underlying analysis
4-29——4.32
Global and Chinese markets of AC electromechanical relays 2022-2028: Research Report on technology, participants, trends, market size and share
[opengl] face pinching system
[engine development] rendering architecture and advanced graphics programming
ASTC texture compression (adaptive scalable texture compression)