当前位置:网站首页>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)
边栏推荐
- Niuke bm83 string deformation (case conversion, string inversion, string replacement)
- PS tips - draw green earth with a brush
- How to color ordinary landscape photos, PS tutorial
- Global and Chinese market of air cargo logistics 2022-2028: Research Report on technology, participants, trends, market size and share
- 【注意力机制】【首篇ViT】DETR,End-to-End Object Detection with Transformers网络的主要组成是CNN和Transformer
- Functional modules and application scenarios covered by the productization of user portraits
- [combinatorics] permutation and combination (set permutation, step-by-step processing example)
- Global and Chinese market of transfer case 2022-2028: Research Report on technology, participants, trends, market size and share
- Rasterization: a practical implementation (2)
- How can entrepreneurial teams implement agile testing to improve quality and efficiency? Voice network developer entrepreneurship lecture Vol.03
猜你喜欢

C language DUP function
![[pytorch learning notes] datasets and dataloaders](/img/c0/9cd539caff34db3cccc44505bbe3c5.png)
[pytorch learning notes] datasets and dataloaders

cpu飙升排查方法

5.4-5.5

4-29——4.32

零拷贝底层剖析

Adobe Premiere Pro 15.4 has been released. It natively supports Apple M1 and adds the function of speech to text

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

How can entrepreneurial teams implement agile testing to improve quality and efficiency? Voice network developer entrepreneurship lecture Vol.03

PS tips - draw green earth with a brush
随机推荐
Déformation de la chaîne bm83 de niuke (conversion de cas, inversion de chaîne, remplacement de chaîne)
. Net six design principles personal vernacular understanding, please correct if there is any error
4-29——4.32
Byte practice surface longitude
Awvs batch operation script
C language DUP function
There are links in the linked list. Can you walk three steps faster or slower
Class part2
B2020 分糖果
复合类型(自定义类型)
使用JMeter对WebService进行压力测试
[transform] [practice] use pytoch's torch nn. Multiheadattention to realize self attention
Global and Chinese market of trimethylamine 2022-2028: Research Report on technology, participants, trends, market size and share
B2020 points candy
[engine development] rendering architecture and advanced graphics programming
C language STR function
零拷贝底层剖析
Joomla! CMS 3.0~3.4.6 RCE
TPS61170QDRVRQ1
What is embedding (encoding an object into a low dimensional dense vector), NN in pytorch Principle and application of embedding