当前位置:网站首页>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)
边栏推荐
- Zzuli:1059 highest score
- ASTC texture compression (adaptive scalable texture compression)
- Leetcode sword offer find the number I (nine) in the sorted array
- Center and drag linked global and Chinese markets 2022-2028: Research Report on technology, participants, trends, market size and share
- C language DUP function
- C # realizes the login interface, and the password asterisk is displayed (hide the input password)
- [ue4] HISM large scale vegetation rendering solution
- . Net six design principles personal vernacular understanding, please correct if there is any error
- How can entrepreneurial teams implement agile testing to improve quality and efficiency? Voice network developer entrepreneurship lecture Vol.03
- 复合类型(自定义类型)
猜你喜欢

On MEM series functions of C language

Remote server background hangs nohup

el-switch 赋值后状态不变化

Influxdb2 sources add data sources

Rasterization: a practical implementation (2)
![[graphics] adaptive shadow map](/img/93/a6a3c7716331368c90c2c86da11f55.jpg)
[graphics] adaptive shadow map

【可能是全中文网最全】pushgateway入门笔记

Incluxdb2 buckets create database

【Transform】【NLP】首次提出Transformer,Google Brain团队2017年论文《Attention is all you need》

Bucket sorting in C language
随机推荐
Adobe Premiere Pro 15.4 has been released. It natively supports Apple M1 and adds the function of speech to text
[combinatorics] permutation and combination (set combination, one-to-one correspondence model analysis example)
解决pushgateway数据多次推送会覆盖的问题
What is one hot encoding? In pytoch, there are two ways to turn label into one hot coding
C string format (decimal point retention / decimal conversion, etc.)
[pytorch learning notes] datasets and dataloaders
【Transform】【实践】使用Pytorch的torch.nn.MultiheadAttention来实现self-attention
Global and Chinese markets for sterile packaging 2022-2028: Research Report on technology, participants, trends, market size and share
从书本《皮囊》摘录的几个句子
Global and Chinese market of postal automation systems 2022-2028: Research Report on technology, participants, trends, market size and share
Simulation of LS -al command in C language
4-20-4-23 concurrent server, TCP state transition;
Introduction to opengl4.0 tutorial computing shaders
【pytorch学习笔记】Datasets and Dataloaders
Web server code parsing - thread pool
5.4-5.5
Fundamentals of PHP deserialization
Qt development - scrolling digital selector commonly used in embedded system
Yolov5进阶之八 高低版本格式转换问题
Troubleshooting method of CPU surge